ACboy needs your help

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5589    Accepted Submission(s):
3043

Problem Description
ACboy has N courses this term, and he plans to spend at
most M days on study.Of course,the profit he will gain from different course
depending on the days he spend on it.How to arrange the M days for the N courses
to maximize the profit?
 
Input
The input consists of multiple data sets. A data set
starts with a line containing two positive integers N and M, N is the number of
courses, M is the days ACboy has.
Next follow a matrix A[i][j],
(1<=i<=N<=100,1<=j<=M<=100).A[i][j] indicates if ACboy spend j
days on ith course he will get profit of value A[i][j].
N = 0 and M = 0 ends
the input.
 
Output
For each data set, your program should output a line
which contains the number of the max profit ACboy will gain.
 
Sample Input
2 2
1 2
1 3
2 2
2 1
2 1
2 3
3 2 1
3 2 1
0 0
 
Sample Output
3
4
6
 
题意:N个任务M天完成,每个任务花费每天都有一定的收益,问收益最大
分析:分组背包
把N个任务看成N组,其中每组中只能选择一个,也就是每一个任务花费的天数肯定是一个数,然后花费的天数还有费用,分组背包纯裸模板
http://www.cppblog.com/Onway/archive/2010/08/09/122695.html这个讲讲解了第二重和三重循环的设计思路
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX = ;
int n,m;
int dp[MAX],a[MAX][MAX];
int main()
{
while(scanf("%d%d", &n, &m) != EOF)
{
if(n == && m == )
break;
for(int i = ; i <= n; i++)
for(int j = ; j <= m; j++)
scanf("%d", &a[i][j]);
memset(dp, , sizeof(dp));
for(int i = ; i <= n; i++)
{
for(int j = m; j > ; j--)
{
for(int k = ; k <=m; k++)
{
if(j >= k)
dp[j] = max(dp[j], dp[j - k] + a[i][k]);
}
}
}
printf("%d\n", dp[m]);
}
return ;
}
 

HD1712ACboy needs your help(纯裸分组背包)的更多相关文章

  1. hdu4003详解(树形dp+多组背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4003 Find Metal Mineral Time Limit: 2000/1000 MS (Jav ...

  2. dp--分组背包 P1757 通天之分组背包

    题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品相互冲突,现在,他想知道最大 ...

  3. ACboy needs your help-分组背包模板题

    id=17676" target="_blank" style="color:blue; text-decoration:none">ACboy ...

  4. D - 英文题 (多组背包)

    The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a gian ...

  5. HDU 3449 Consumer (背包问题之有依赖背包)

    题目链接 Problem Description FJ is going to do some shopping, and before that, he needs some boxes to ca ...

  6. 【题解】洛谷P1273 有线电视网(树上分组背包)

    次元传送门:洛谷P1273 思路 一开始想的是普通树形DP 但是好像实现不大好 观摩了一下题解 是树上分组背包 设f[i][j]为以i为根的子树中取j个客户得到的总价值 我们可以以i为根有j组 在每一 ...

  7. (第三场) A PACM Team 【dp,五维背包】

    链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  8. hdu 3535 背包综合题

    /* 有n组背包,每组都有限制 0.至少选一项 1.最多选一项 2.任意选 */ #include <iostream> #include <cstdio> #include ...

  9. HDU3535 AreYouBusy 混合背包

    题目大意 给出几组物品的体积和价值,每组分为三种:0.组内物品至少选一个:1.组内物品最多选一个:2.组内物品任意选.给出背包容量,求所能得到的最大价值. 注意 仔细审题,把样例好好看完了再答题,否则 ...

随机推荐

  1. openstack通过salt-cloud创建虚拟机

    saltstack有三大功能:远程执行.配置管理.云管理:saltstack的云管理就是通过salt-cloud完成的,salt-cloud是基于openstack来做的:salt-cloud能够管理 ...

  2. Myeclipse+maven时Tomcat部署时maven的依赖文件不能部署到Tomcat上

    解决办法:

  3. 【.NET进阶】函数调用--函数栈

    原文:http://www.cnblogs.com/rain-lei/p/3622057.html 函数调用大家都不陌生,调用者向被调用者传递一些参数,然后执行被调用者的代码,最后被调用者向调用者返回 ...

  4. CentOS7 SSH相关

    1.查看SSH是否已经安装,命令: rpm -qa |grep ssh 如果列出了openssh-x.x开头的软件名,代表已经安装 如果没有安装,使用命令安装: yum install ssh 2.如 ...

  5. HTTP协议简介2

    几个相关的知识点: 客户端发送请求时,请求类型为GET与POST的主要差别是什么? 1.请求类型不同,一个为GET,一个为POST 2.当请求类型为GET时,请求的数据以参数的形式添加到url的后面, ...

  6. 用postgreSQL做基于地理位置的app(zz)

    前言:项目中用到了postgreSQL中的earthdistance()函数功能计算地球上两点之间的距离,中文的资料太少了,我找到了一篇英文的.讲的很好的文章,特此翻译,希望能够帮助到以后用到eart ...

  7. Activiti系列——如何在eclipse中安装 Activiti Designer插件

    这两天在评估jbpm和Activiti,需要安装一个Activiti Designer插件试用一下. 一.在线安装 从<Activiti实战>了解到可以通过如下方式安装 打开Eclipse ...

  8. html5新增选择器

    分享点html5的学习笔记,比较基础,突然发现通过写博客来记笔记有很多优点呢,平常记得笔记比较简单,复习起来比较吃力,看自己的博客理解起来还比较轻松,而且只有真正理解了才能表达清楚让别人看懂,还锻炼语 ...

  9. 编写高质量代码--改善python程序的建议(六)

    原文发表在我的博客主页,转载请注明出处! 建议二十八:区别对待可变对象和不可变对象 python中一切皆对象,每一个对象都有一个唯一的标识符(id()).类型(type())以及值,对象根据其值能否修 ...

  10. WPF开发时光之痕日记本(一)——富文本编辑器

    本篇给大家推荐一个 WPF 版的富文本编辑器,SmithHtmlEditor,具体网址大家可以找一找,我在这个编辑器的基础上修改了界面,增加了一些功能,模仿了kindeditor 的界面,鉴于自己现在 ...