转载请注明出处:http://blog.csdn.net/u012860063

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

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门课,m代表你有m天,

然后给你一个数组,val[i][j],代表第i门课,在通过j天去修,

会得到的分数。求在m天能得到的最大分数。

#include <cstdio>
#include <cstring>
#define N 147
int max(int a, int b)
{
if(a > b)
return a;
return b;
}
int main()
{
int n,m,a[N][N],dp[N];
int i, j, k;
while(~scanf("%d%d",&n,&m)&&( n || m))
{
memset(dp,0,sizeof(dp));
for(i = 1; i <=n ; i++)
{
for(j = 1; j <= m ;j++)
scanf("%d",&a[i][j]);
}
for(i = 1 ; i <= n ; i++)//第一重循环:分组数
{
for(j = m ; j >= 1 ; j--) //第二重循环:容量体积
{
for(k = 1 ; k <= j ; k++) //第三重循环:属于i组的k
{
dp[j]=max(dp[j],dp[j-k]+a[i][k]);
}
}
}
printf("%d\n",dp[m]);
}
return 0;
}

最新文章

  1. 关于Unity3D手机网游开发一些小看法
  2. Qt编程之mapx组件编程
  3. JSP内置对象有哪些呢?
  4. 不可或缺 Windows Native (23) - C++: 虚函数
  5. Qt之QSystemTrayIcon
  6. python challenge第1关--NoteBook上的“乱码”
  7. hdu 4628 动态规划
  8. Function 语意学
  9. mac上搭建appium环境过程以及遇到的问题
  10. Mybatis JPA 代码构建
  11. highchart
  12. dataframe常用处理
  13. (Python基础)最Low三级菜单
  14. Innobackupex(xtrabackup)物理备份
  15. Scriter CSS
  16. Centos 中 vi 和vim 的区别
  17. oracle 中decode函数用法
  18. Java反射机制介绍
  19. Android开发训练之第五章第四节——Syncing to the Cloud
  20. python 模块被引用多次但是里面的全局表达式总共只会执行一次

热门文章

  1. 转: Linux 技巧:让进程在后台可靠运行的几种方法
  2. 解决windows下vim方向键变成 ABCD 的问题
  3. sencha项目升级
  4. Java [Leetcode 226]Invert Binary Tree
  5. js判断checkbox是否已选
  6. JPA---一对一关系
  7. C#.NET开源项目、机器学习、商务智能
  8. gdi写的2048
  9. error MSB3027: Could not copy &quot;xxx.dll&quot; to &quot;xxx.dll&quot;. Exceeded retry count of 10. Failed.
  10. selenium 调用JS操作滚动条(java)来解决element not clickable的问题