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 ...
随机推荐
- OAuth2.0-2jwt令牌
JWT令牌 解决了之前普通令牌每次都要远程校验令牌带来得网络消耗:(有网友说可以将令牌验证从认证服务器上放到各个资源服务器上,不知是否可行?) JWT令牌的优点: 1.jwt基于json,非常方便解析 ...
- Android 布局的一些控件的补充和布局的补充(今儿没课)
前面写的博客可能会有点乱: 1,是不太会排版. 2,就是我一边看书,一边听学长讲课,所以有的知识就融入进去了,我写的都是自己的意见和理解,大家取我精华,弃我糟粕哈. 今天是书上的内容,主要讲布局的,一 ...
- three.js 着色器材质之变量(一)
上一篇说顶点着色器和片元着色器的皮毛,这篇郭先生说一说着色器变量,通过变量可以设置材质.先看看今天要做的如下图.在线案例请点击博客原文. 在这个案例之前,我们先复习一下着色器变量 Uniforms是所 ...
- Secure CRT连接VMware虚拟机中的CentOS 7
操作步骤: 1.安装Centos 7 虚拟机设置==>NetworkAdapter===>选择NAT(共享主机的IP地址), CTRL+ALT+F1切换到图形界面 选择右上角以太网打开 ...
- SpringCloudAlibaba-服务容错Sentinel(入门)
一:高并发带来的问题? 在微服务架构中,我们将业务拆分成一个个的服务,服务与服务之间可以相互调用,但是由于网络原因或者自身的原因,服务并不能保证服务的100%可用,如果单个服务出现问题,调用这个服务就 ...
- [学习笔记] Numpy基础 系统学习
[学习笔记] Numpy基础 上专业选修<数据分析程序设计>课程,老师串讲了Numpy基础,边听边用jupyter敲了下--理解+笔记. 老师讲的很全很系统,有些点没有记录,在PPT里就不 ...
- C# winform 弹出窗体给父窗体传值
Winform程序有很多传值的方法,抱着学习的态度.利用委托注册事件的方法,给窗体统一添加事件: 首先定义一个Frm_Base: namespace 任意 { public partial class ...
- vue2和vue3的区别
一.常用命令 vue -V 查看本地 vue 版本 二.官方文档 3.0:https://cli.vuejs.org/zh/ 三.创建文件 3.0:vue create 进入工程文件夹,创建项目. 2 ...
- unity探索者之UGUI圆形图片组件
版权声明:本文为原创文章,转载请声明https://www.cnblogs.com/unityExplorer/p/13524824.html 使用UGUI进行游戏开发的过程中经常会遇到一个问题:玩家 ...
- generate_fixed_frame()方法生成Java方法栈帧
在从generate_normal_entry()函数调用generate_fixed_frame()函数时的栈与寄存器的状态如下: 栈的状态如下图所示. 各个寄存器的状态如下所示. rax: ret ...