ACboy needs your help-分组背包模板题
| Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
profit?
Input
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
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
/*
Author: 2486
Memory: 1456 KB Time: 93 MS
Language: G++ Result: Accepted
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn=100+5;
int dp[maxn],a[maxn][maxn];
int n,m;
int main() {
while(~scanf("%d%d",&n,&m),n&&m) {
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
scanf("%d",&a[i][j]);
}
}
memset(dp,0,sizeof(dp));
int Max=0;
for(int i=1; i<=n; i++) {
for(int k=m; k>=0; k--) {
for(int j=1; j<=m; j++) {
if(k-j<0)break;
dp[k]=max(dp[k],dp[k-j]+a[i][j]);
}
}
}
printf("%d\n",dp[m]);
}
return 0;
}
ACboy needs your help-分组背包模板题的更多相关文章
- HDU 1712 ACboy needs your help (分组背包模版题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...
- HDU1712:ACboy needs your help(分组背包模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem Description ACboy has N courses this term, an ...
- 分组背包模板题 hdu1712
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 第一次接触分组背包,参考博客:https://blog.csdn.net/yu121380/ar ...
- D. Arpa's weak amphitheater and Mehrdad's valuable Hoses 分组背包模板题
http://codeforces.com/problemset/problem/742/D 并查集预处理出所有关系. 一开始的时候,我预处理所有关系后,然后选择全部的时候,另起了一个for,然后再判 ...
- HDU 2602 - Bone Collector - [01背包模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...
- HDU 1114 Piggy-Bank(完全背包模板题)
完全背包模板题 #include<cstdio> #include<cstring> #include<algorithm> using namespace std ...
- HDU 2191 珍惜现在,感恩生活(多重背包模板题)
多重背包模板题 #include<iostream> #include<cstring> #include<algorithm> using namespace s ...
- HDU - 1712 (分组背包模板)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意:给你n个课程,每个课程有很多种学习方法,用的时间和取得的效果都不一样,现在你只有m天时间用来学 ...
- 51nod 1086背包问题V2 (完全背包模板题)
1086 背包问题 V2 1 秒 131,072 KB 20 分 3 级题 题目描述 有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1, ...
随机推荐
- Unordered load/store queue
A method and processor for providing full load/store queue functionality to an unordered load/store ...
- 中断处理函数中不用disable_irq而用disable_irq_nosync原因【转】
转自:http://blog.csdn.net/beyondioi/article/details/9201695 今天在写触摸屏驱动时在中断处理函数中使用disable_irq关中断发现在进入中断处 ...
- (十二)进一步掌握STVD/COSMIC
如何分配变量到指定的地址 举例:unsigned char temp_A@0x00; //定义无符号变量temp_A,强制其地址为0x00unsigned char temp_B@0x100; //定 ...
- Linux设置编译器环境变量
Linux设置编译器环境变量 https://jingyan.baidu.com/article/9f7e7ec0bb22aa6f29155453.html Linux添加环境变量与GCC编译器添加I ...
- AOP相关
静态代理.动态代理与AOP: 简单易懂:http://blog.csdn.net/hejingyuan6/article/details/36203505 补充:http://layznet.itey ...
- StringUtils.isEmpty()和StringUtils.isBlank() 区别
isBlank()判断空的情况包括了isEmpty()的情况,isBlank()不仅判断了 无对象.空对象的情况,而且也判断了无意义的空白字符,比如空格等.
- mybatis insert oracle 返回主键
mybtis返回oracle主键 只需要加一点代码(红色处的代码)就可以了 <!-- 添加记录到临时表 --> <insert id="insertPlaneStateme ...
- 肢解 HTTP 服务器构建
更好阅读请戳 这里 1. 最简单的 http 服务器 // server.js var http = require("http"); http.createServer(func ...
- FluentValidation具体使用案例
可以使用NuGet 添加类库 下面是程序: using FluentValidation; using System; using System.Linq; namespace TestFluen ...
- mysql:functional dependency
0down vote First, a functional dependency in the form A->B means that, given one value for A, we ...