ACboy needs your help

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

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
 
Source
 
分组背包,背包容量m,物品分为n组,每组只能取一件,求背包最大价值。
dp[i][j]表示对于前i组物品,背包容量为j时的最大价值,此时对于每种dp[i][j]需要遍历第i组的每一个物品,求出最大的dp[i][j];
 
状态转移方程:
          dp[i][j]=max(dp[i][j],dp[i-1][j-k]+ma[i][k])
 
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define Max 105
int dp[Max][Max],ma[Max][Max];
int n,m;
int main()
{
int i,j;
memset(ma,,sizeof(ma));
freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m))
{
if(n==&&m==)
break;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&ma[i][j]);
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
for(int k=;k<=j;k++)
{
if(dp[i][j]<dp[i-][j-k]+ma[i][k])
dp[i][j]=dp[i-][j-k]+ma[i][k];
}
//cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
printf("%d\n",dp[n][m]);
}
return ;
}
 

ACboy needs your help(HDU 1712 分组背包入门)的更多相关文章

  1. hdu 1712 (分组背包入门)

    http://acm.hdu.edu.cn/showproblem.php?pid=1712 问题 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].这些物品被划分为若干组, ...

  2. HDU 1712 分组背包

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

  3. ACboy needs your help HDU - 1712

    ACboy needs your help HDU - 1712 ans[i][j]表示前i门课共花j时间最大收益.对于第i门课,可以花k(0<=k<=j)时间,那么之前i-1门课共花j- ...

  4. P1757 通天之分组背包 / hdu1712 ACboy needs your help (分组背包入门)

    P1757 通天之分组背包 hdu1712 ACboy needs your help hdu1712题意:A[i][j]表示用j天学习第i个课程能够得到A[i][j]的收益,求m天内获得的收益最大值 ...

  5. HDU 3033 分组背包变形(每种至少一个)

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 4341 分组背包

    B - Gold miner Time Limit:2000MS      Memory Limit:32768KB     Description Homelesser likes playing ...

  7. HDU 3033 分组背包(至少选一个)

    分组背包(至少选一个) 我真的搞不懂为什么,所以现在就只能当作是模板来用吧 如果有大牛看见 希望评论告诉我 &代码: #include <cstdio> #include < ...

  8. HDU 1712 ACboy needs your help 典型的分组背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 ACboy needs your help Time Limit: 1000/1000 MS ( ...

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

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

随机推荐

  1. Java添加自定义注解

    今天在整合MyBatis过程中,我使用扫描的方式去扫描DAO目录下的Java文件,但是在Service层使用Autowired的时候报错,但是工程能正常运行,此处有Bug! 解决方案: 1.创建 an ...

  2. 设置iOS项目BuildVersion自动增加-备用

    一.概念阐述:Build与Version的区别 在iOS中有两种“版本号”,也就是所谓的version号与build号,如下图所示: 我们用最简洁的语言来区分这两个版本号的区别以及用途如下: Vers ...

  3. (摘)oracle dataguard切换

    众所周知,Data Guard已经是现今标准的主流容灾方案,由于日志传递对于网络适应程度强,且可以采用同步实时的传递方式和异步延迟的传递方式,甚至可以成为远程的异地容灾方案.不管用于何种用途,DG都免 ...

  4. ultraedit替换所有空白行 --正则表达式使用

    ultraedit替换所有空白行 --正则表达式使用 删除空行: 替换 %[ ^t]++^p 为 空串 删除行尾空格: 替换 [ ^t]+$ 为 空串 删除行首空格: 替换 %[ ^t]+ 为 空串 ...

  5. 段错误bug的调试

    我们在用C/C++语言写程序的时侯,内存管理的绝大部分工作都是需要我们来做的.实际上,内存管理是一个比较繁琐的工作,无论你多高明,经验多丰富,难 免会在此处犯些小错误,而通常这些错误又是那么的浅显而易 ...

  6. jquery 的ready() 与window.onload()的区别

    做web开发时常用Jquery中$(document).ready()和JavaScript中的window.onload方法,两者都是要在页面加载完成以后加载的方法,但是这两者还是有很大区别的.最近 ...

  7. Permutations 解答

    Question Given a collection of numbers, return all possible permutations. For example,[1,2,3] have t ...

  8. shell惊鸿

    显示当前用户uid

  9. Web开发之RSET API

    REST介绍 如果要说什么是REST的话,那最好先从Web(万维网)说起. 什么是Web呢?读者可以查看维基百科的词条(http://zh.wikipedia.org/zh-cn/Web),具体的我就 ...

  10. fdm_search_info_w_book_chain

    数据知识管理平台-元数据管理-fdm_search_info_w_book_chain-详细信息 fdm_search_info_w_book_chain