ACboy needs your help

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

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
 
 
题目意思:
有n个课程,每个课程在不同天数得到不同价值,总共m天,问m天之内得到最大的价值。
 
思路:
每个课程若在i天完成,就不能在j天完成。以n个课程为组,天数为体积,价值为价值,即得到分组背包的模型。
 
dp[i][j]=max(dp[i-1][j],dp[i-1][j-v[k]]+w[k])//dp[i][j]表示前i组已占用j体积时最大价值。
 
代码:
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 105 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} int a[N][N];
int n, m;
int dp[N]; main()
{
int i, j, k;
while(scanf("%d %d",&n,&m)==){
if(!n&&!m) break;
for(i=;i<=n;i++){
for(j=;j<=m;j++)
scanf("%d",&a[i][j]);
}
memset(dp,,sizeof(dp));
for(i=;i<=n;i++){
for(j=m;j>=;j--){
for(k=;k<=j;k++){
dp[j]=max(dp[j],dp[j-k]+a[i][k]);
}
}
}
printf("%d\n",dp[m]);
}
}

最新文章

  1. Extjs API - JS Duck
  2. 【MSDN原版】Windows 7 with SP1各版本下载
  3. 深度学习入门教程UFLDL学习实验笔记一:稀疏自编码器
  4. 小组开发项目NABC分析
  5. HW-文件恢复-测试300
  6. 使用 Infragistics 的 NetAdvantage 组件时替换部分菜单语言的方法
  7. 贝叶斯分类器(Bayes分类器)
  8. Playfair 加密
  9. 原生JS实现banner图的滚动与跳转
  10. /*+ hint*/用法,该如何解决
  11. PHP从入门到精通(四)
  12. MySQL5.6复制技术(3)-MySQL主从复制线程状态转变
  13. 【Python】基础知识
  14. StanFord ML 笔记 第十部分
  15. django序列化单表的4种方法的介绍
  16. 如何通俗理解贝叶斯推断与beta分布?
  17. python16_day01【介绍、基本语法、流程控制】
  18. crm--业务点详细概述
  19. C++ 调用Python3
  20. C++关于堆的函数

热门文章

  1. linux ‘|’ 与重定向 实例详解
  2. VBS整人代码
  3. GOLANG 变量
  4. js创建节点及其属性
  5. 解决qt程序运行时的cannot create Qt for Embedded Linux data directory: /tmp/qtembedded-0出错情形
  6. 我的git学习
  7. godep 包管理工具
  8. php : MVC 演示(使用单例工厂)
  9. logback 配置详解(一)——logger、root
  10. thinkphp3.1.3中widget用法