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个课程和有m天,在输入n*m的矩阵,分别代表经历j天在i课程上,得到的一个权值,求大的权值。
#include <iostream>
#include <cstring>
using namespace std;
int a[][],dp[];
int n,m;
int main()
{
while(cin>>n>>m,n||m)
{
memset(dp,,sizeof dp);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
cin>>a[i][j];
for(int i=;i<=n;i++)
for(int j=m;j>=;j--)
for(int k=;k<=j;k++)///枚举在i课程的天数
dp[j]=max(dp[j],dp[j-k]+a[i][k]);
cout<<dp[m]<<'\n';
}
return ;
}

 

最新文章

  1. 【java开发】ubuntu常用命令及环境搭建
  2. angularjs 设置全局变量的3种方法
  3. 应用程序框架实战十五:DDD分层架构之领域实体(验证篇)
  4. Oauth2.0 用Spring-security-oauth2 来实现
  5. Self Numbers 分类: POJ 2015-06-12 20:07 14人阅读 评论(0) 收藏
  6. 用NGUI做一个计时条!
  7. JQuery重要知识点
  8. CodeForces - 508D Tanya and Password(欧拉通路)
  9. hdu2899 Strange fuction
  10. windows下cmd命令行上传代码到github的指定库
  11. Oracle数据库联机重定义讲解及错误处理
  12. MVC架构介绍-框架分层
  13. C#会对于未赋值的变量/成员变量,给予一个初始值吗?
  14. samba服务器配置及window网络磁盘映射
  15. win10+anaconda3+python3.6+opencv3.1.0
  16. R语言学习——循环判断语句
  17. 刚才在windows下发现拖拽不了文件了
  18. 把模块有关联的放在一个文件夹中 在python2中调用文件夹名会直接失败 在python3中调用会成功,但是调用不能成功的解决方案
  19. C#与C++区别
  20. git分支在团队中的使用

热门文章

  1. Lock wait timeout exceeded; try restarting transaction linux设置mysql innodb_lock_wait_timeout
  2. find missing conjunction, why?
  3. 简单记录下@RequestBody(关于它和@RequestParam接收数据方式的拓展)
  4. C. Arpa&#39;s loud Owf and Mehrdad&#39;s evil plan DFS + LCM
  5. D. Black Hills golden jewels 二分答案 + 二分判定
  6. Java迭代器的用法【转】
  7. SonarQube+Svn+Jenkins环境搭建----问题总结
  8. 动手实现 React-redux(三):connect 和 mapStateToProps
  9. idea 下maven 导入本地jar,以及导入之后 java不能引用问题
  10. 洛谷 P1030 求先序排列