题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712

ACboy needs your help

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

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
 
解题思路:背包问题,每门课不管多少时间只能选一次,所以是典型的分组背包问题。
 
想深究可以去看《背包九讲》,把背包问题讲的很详细
 
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int keng[][];
int dp[];
int main()
{
int n,m,i,j,k;
while(scanf("%d%d",&n,&m),n+m!=)
{
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
scanf("%d",&keng[i][j]);
}
for(i=n;i>;i--)
for(j=m;j>=;j--)
for(k=;k<=j;k++)
if(dp[j]<dp[j-k]+keng[i][k])
dp[j]=dp[j-k]+keng[i][k];
printf("%d\n",dp[m]);
}
return ;
}

HDU 1712 ACboy needs your help 典型的分组背包的更多相关文章

  1. HDU 1712 ACboy needs your help(包背包)

    HDU 1712 ACboy needs your help(包背包) pid=1712">http://acm.hdu.edu.cn/showproblem.php? pid=171 ...

  2. HDU 1712 ACboy needs your help (分组背包模版题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...

  3. 分组背包 例题:hdu 1712 ACboy needs your help

    分组背包需求 有N件物品,告诉你这N件物品的重量以及价值,将这些物品划分为K组,每组中的物品互相冲突,最多选一件,求解将哪些物品装入背包可使这些物品的费用综合不超过背包的容量,且价值总和最大. 解题模 ...

  4. HDU 6125 Free from square(状态压缩+分组背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=6125 题意: 在${1,2,3,...n}$的数中选择1~k个数,使得它们的乘积不能被平方数整除(1除外),计算 ...

  5. hdu 1712 ACboy needs your help 分组背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem ...

  6. hdu 1712 ACboy needs your help

    ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. HDU 1712 ACboy needs your help(分组背包入门题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意: 有个人学习n门课程,a[i][j]表示用j分钟学习第i门课程所能获得的价值,背包容量为一共有m时间 ...

  8. HDU 1712 ACboy needs your help(分组背包)

    题意:给你n的课程组,每个课程组有m个课程,每个课程有一个完成时间与价值.问在m天内每组课程组最多选择一个,这样可以得到的最大价值是多少 题解:分组背包,其实就是每个课程组进行01背包,再在课程组内部 ...

  9. HDU - 1712 - ACboy needs your help 【分组背包】

    <题目链接> 题目大意:有n个课程,现在花M天来学习这些课程,学习每个课程花的天数所得到的价值不同,求M天怎么分配学习才能得到的价值最大.(这些课程得到的价值和所花天数的关系由矩阵给出) ...

随机推荐

  1. 【转】Vim命令合集以及乱码问题解决

    乱码问题 """""""""""""""" ...

  2. Wap站总结一

    前段时间负责了公司的wap站前端工作,目前wap站的基础及较为复杂的几张页面都已经出来,现根据自己的一些经验,贴出部分心得,希望对现在或者以后可能会接触到Wap站的一些人有些帮助 一.本次WAP网站的 ...

  3. (jQuery 插件)封装容器的表单为json对象

    下面代码可以把一个页面容器中的表单元素封装成一个json对象. (function($){ $.fn.serializeObject=function(){ var inputs=$(this).fi ...

  4. jquery中onclick内$(this)指向

    jquery中onclick=”fn”中$(this)所代表的对象 js方法 function qiehuan(){ var src = $(this).attr(“data”); alert($(t ...

  5. WPF界面特殊字符处理

          界面XAML不支持< .>.&."等字符. 使用字符实体编码进行替代,以下是pro WPF 4.5的摘要表 Special Character        ...

  6. hdu10007

    题意,很简单,给n个点的坐标,求距离最近的一对点之间距离的一半. 第一行是一个数n表示有n个点,接下来n行是n个点的x坐标和y坐标.实数. 这个题目其实就是求最近点对的距离   #include< ...

  7. Pentaho Data Integration (三) Pan

    官网连接: http://wiki.pentaho.com/display/EAI/Pan+User+Documentation Pan Pan 是一个可以执行使用Spoon编辑的transforma ...

  8. DM8168 编译filesystem步骤

    在板子跑起来之前,需要先编译好8168的文件系统.前提是已经设置好板子的类型等参数,详见<DM8168环境搭建> 1.进入<DVR_RDK_BASE>/dvr_rdk目录 ma ...

  9. ReactEurope Conf 参会感想

    React 带来的革命性创新是前端世界过去几年最激动人心的变化.自从接触 React 以来,我深信 React 会改变客户端开发者(包括前端.iOS 和 Android)的开发体验.这次在巴黎举办的  ...

  10. ubuntu修改grub2

    转自修改系统启动项 grub2配置的方法 ubuntu 在早期的Ubuntu中,使用Grub作为系统的启动引导程序,想修改系统启动项非常简单,只要用gedit打开系统菜单设定文件( sudo gedi ...