ACboy needs your help (动态规划背包)
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
题解:动态规划背包问题,三重循环解即可
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0||m==0)
{
break;
}
long long int dp[105];
int a[105][105];
memset(dp,0,sizeof(dp));
memset(a,0,sizeof(a));
for(int t=1;t<=n;t++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&a[t][j]);
}
}
for(int t=1;t<=n;t++)
{
for(int j=m;j>=0;j--)
{
for(int k=0;k<=j;k++)
{
dp[j]=max(dp[j],dp[j-k]+a[t][k]);
}
}
}
printf("%lld\n",dp[m]);
}
return 0;
}
ACboy needs your help (动态规划背包)的更多相关文章
- HDU 1712 ACboy needs your help(包背包)
HDU 1712 ACboy needs your help(包背包) pid=1712">http://acm.hdu.edu.cn/showproblem.php? pid=171 ...
- Bzoj 1042: [HAOI2008]硬币购物 容斥原理,动态规划,背包dp
1042: [HAOI2008]硬币购物 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1747 Solved: 1015[Submit][Stat ...
- Leetcode 494 Target Sum 动态规划 背包+滚动数据
这是一道水题,作为没有货的水货楼主如是说. 题意:已知一个数组nums {a1,a2,a3,.....,an}(其中0<ai <=1000(1<=k<=n, n<=20) ...
- HDU1712:ACboy needs your help(分组背包模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem Description ACboy has N courses this term, an ...
- hdu 3008:Warcraft(动态规划 背包)
Warcraft Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu1712 ACboy needs your help 分组背包
最基础的分组背包~ #include <iostream> #include <cstdio> #include <cstdlib> #include <cs ...
- HDU 1712 ACboy needs your help (分组背包模版题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...
- hdu 1712 ACboy needs your help 分组背包
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem ...
- POJ_2184_Cow_Exhibition_(动态规划,背包)
描述 http://poj.org/problem?id=2184 n只奶牛,每只都有智商s_i和情商f_i,取出若干只,保证智商之和与情商之和都不为负的情况下,让两者之和最大. Cow Exhibi ...
随机推荐
- Nginx的基本使用和配置
2.1什么是Nginx Nginx 是一款高性能的 http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师伊戈尔·西索夫(Igor Sysoev)所开发,官方 ...
- Rx.js实现原理浅析
前言 上次给大家分享了cycle.js的内容,这个框架核心模块的代码其实只有一百多行,要理解这个看似复杂的框架,其实最核心的是理解它依赖的异步数据流处理框架--rx.js.今天,给大家分享一下rx.j ...
- python8.4景区买票
from threading import Threadimport threadinglock=threading.Lock()num=100#定义买票方法def sale(name): lock. ...
- 再见,付费录屏软件!我用70行Python代码打造免费版!
- 为何选择spark!
随着大数据处理的应用场景越来越多,人们对Hadoop的要求也越来越高,开发出的对应的系统也越来越多,人们迫切的需要一个综合的计算框架,Spark应运而生,我们可以看看Spark可以干些什么. 那么为什 ...
- PYTHON实战完整教程1-配置VSCode开发环境
一.安装 为降低学习门槛,保证学习目标的聚焦,我们在windows(使用WinServer2019虚拟机)上搭建开发环境.(系列教程最后结束时,也会部署到linux上) 打开Python官网 http ...
- 申请支付宝app支付签约综合评分不足,拒绝不通过快速强开通支付宝App支付强开,强开支付宝App支付产品权限!
一.如何开通支付宝App支付 正常来说,按照官方的指引要求填写相关资料,即可开通支付宝手机网站支付.但是,更多的时候我们的申请都会碰到一些阻力,常见的阻力就是“系统综合评估签约条件不满足,谢谢您的支持 ...
- C#LeetCode刷题之#242-有效的字母异位词(Valid Anagram)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4040 访问. 给定两个字符串 s 和 t ,编写一个函数来判断 ...
- NeuralCoref: python的共指消解工具教程
转载地址 https://blog.csdn.net/blmoistawinde/article/details/81782971 共指消解 首先简要地说说共指消解是什么,有什么用处.假设机器正在阅读 ...
- Spring/Springboot——JavaConfig
1.认识JavaConfig JavaConfig是Spring的一个子项目,在Spring4之后成为一个核心功能 JavaConfig中使用的注解: @Configuration 在类上打上这一标签 ...