Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u

Submit Status

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
 
/*
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-分组背包模板题的更多相关文章

  1. HDU 1712 ACboy needs your help (分组背包模版题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...

  2. HDU1712:ACboy needs your help(分组背包模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem Description ACboy has N courses this term, an ...

  3. 分组背包模板题 hdu1712

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 第一次接触分组背包,参考博客:https://blog.csdn.net/yu121380/ar ...

  4. D. Arpa's weak amphitheater and Mehrdad's valuable Hoses 分组背包模板题

    http://codeforces.com/problemset/problem/742/D 并查集预处理出所有关系. 一开始的时候,我预处理所有关系后,然后选择全部的时候,另起了一个for,然后再判 ...

  5. HDU 2602 - Bone Collector - [01背包模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...

  6. HDU 1114 Piggy-Bank(完全背包模板题)

    完全背包模板题 #include<cstdio> #include<cstring> #include<algorithm> using namespace std ...

  7. HDU 2191 珍惜现在,感恩生活(多重背包模板题)

    多重背包模板题 #include<iostream> #include<cstring> #include<algorithm> using namespace s ...

  8. HDU - 1712 (分组背包模板)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意:给你n个课程,每个课程有很多种学习方法,用的时间和取得的效果都不一样,现在你只有m天时间用来学 ...

  9. 51nod 1086背包问题V2 (完全背包模板题)

    1086 背包问题 V2 1 秒 131,072 KB 20 分 3 级题 题目描述 有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1, ...

随机推荐

  1. kvm的vmcall

    这几个接口的区别在于参数个数的不用,本质是一样的.挑个参数最多的看下: static inline long kvm_hypercall4(unsigned int nr, unsigned long ...

  2. Oracle基础 02 临时表空间 temp

    --查看临时文件的使用/剩余空间 SQL> select * from v$temp_space_header; --查看SCOTT用户所属的临时表空间 SQL> select usern ...

  3. easyUi根据一个日期给另一日期自动赋值的js

    $('#loanbegindate').datebox({ onSelect:function(date){ changeDate(); } }); $('#loanterm,#loantermtyp ...

  4. 几种常用排序算法的python实现

    1:快速排序 思想: 任意选取一个数据(通常选用数组的第一个数)作为关键数据,然后将所有比它小的数都放到它前面,所有比它大的数都放到它后面,这个过程称为一趟快速排序. 一趟快速排序的算法是: 1)设置 ...

  5. k8s的应用打包工具Helm

    每个成功的软件平台都有一个优秀的打包系统,比如 Debian.Ubuntu 的 apt,Redhat.Centos 的 yum.而 Helm 则是 Kubernetes 上的包管理器. 本章我们将讨论 ...

  6. mysql:functional dependency

    0down vote First, a functional dependency in the form A->B means that, given one value for A, we ...

  7. Windows+Ubuntu双系统如何设置Windows为第一启动项

    在安装双系统的时候,如果先安装的是Windows然后再安装Ubuntu系统,开机时是以Ubuntu的grub来引导Windows的,而且默认进入Ubuntu系统,下面我们介绍如何更改这个默认项,然后让 ...

  8. ionic3 打包发布,以安卓说明

    1 添加图标 ionic cordova resources [<platform>] 官方https://ionicframework.com/docs/cli/cordova/reso ...

  9. 【转】C#获取当前程序运行路径的方法集合

    //获取当前进程的完整路径,包含文件名(进程名).string str = this.GetType().Assembly.Location;result: X:\xxx\xxx\xxx.exe (. ...

  10. 一分钟了解ruby中的单测

    之前用gtest写过很多c++的单测case, 对gtest的强大和灵活印象深刻:最近需要用ruby写一个小工具, 接触了下ruby, 写了代码就要写单测啊(好的单测确实对代码的健壮性和正确性保证上太 ...