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]);
}
}

HDU 1712 分组背包的更多相关文章

  1. hdu 1712 (分组背包入门)

    http://acm.hdu.edu.cn/showproblem.php?pid=1712 问题 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].这些物品被划分为若干组, ...

  2. ACboy needs your help(HDU 1712 分组背包入门)

    ACboy needs your help Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. HDU 3033 分组背包变形(每种至少一个)

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 4341 分组背包

    B - Gold miner Time Limit:2000MS      Memory Limit:32768KB     Description Homelesser likes playing ...

  5. HDU 3033 分组背包(至少选一个)

    分组背包(至少选一个) 我真的搞不懂为什么,所以现在就只能当作是模板来用吧 如果有大牛看见 希望评论告诉我 &代码: #include <cstdio> #include < ...

  6. HDU 3033 分组背包

    给出N个物品.M金钱.W种类 给出N个物品的性质:所属种类,花费.价值 求每一种类物品至少一个的前提下,所能购买到的最大价值 dp[i][k]表示在第i种物品.总花费为k的最大价值 dp[i][k]= ...

  7. 背包系列 hdu 3535 分组背包

    题意: 有n组工作,现在有T分钟时间去做一些工作.每组工作里有m个工作,并且类型为s,s类型可以为0,1,2,分别表示至少选择该组工作的一项,至多选择该工作的一项,不限制选择.每个工作有ci,gi两个 ...

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

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

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

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

随机推荐

  1. PHPStorm 与 XDebug 配置

    XDebug 配置 环境 Nginx 1.4.7 32 bit PHP 5.4.25 32 bit Windows 10 64 bit 下载 PHP 5.4 VC9 (32 bit)[nts版本] 配 ...

  2. static变量引起的问题,List数据覆盖

    出现的问题:Listt加载数据时,后面加载的数据会覆盖前面的数据,把后面的数据变得和前面一样 原因:因为刚开始把添加的数据写成了静态变量,所以一个改了以后所有都改了 解决方法:把数据设成普通属性,非静 ...

  3. C#解决一个奇怪的,命名空间“XXX”中不存在类型或命名空间名称“xxx”的问题

    最近做项目时,引用了一个第三方的程序集,代码层面没有任何语法错误,编译提示:命名空间"System.Net"中不存在类型或命名空间名称"FtpClient".是 ...

  4. HTML5滑动(swipe)事件

    移动H5开发中经常用到滑动效果(页面上移.下移.向左滑动.向右滑动等),浏览器并没有内置swipe事件,可以通过touch事件(touchstart.touchmove和touchend)模拟swip ...

  5. java.lang.InstantiationException-反射机制

    package com.test.classtest; public class test { public static void main(String[] args) throws Except ...

  6. [poj2492]A Bug's Life(并查集+补集)

    A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 34678   Accepted: 11339 D ...

  7. MySQL 5.7 解压版安装配置

    测试环境 系统:Windows 10专业版 版本:MySQL Server 5.7.14   提纲 修改配置文件 初始化 安装服务.启动服务 修改root密码   步骤 1.解压安装包 在MySQL官 ...

  8. About vector

    今天打vector又打炸了不!高!兴! vecotr头文件 #include<vector> 定义域 using namespace std; 或using std::vector; 初始 ...

  9. 流媒体测试笔记记录之————阿里云监控、OBS、FFmpeg拉流和推流变化比较记录

    OBS设置视频(512kbps)和音频(128kbps)比特率 阿里云监控结果: 使用FFmpeg拉流到Nginx 服务器测试比特率 第二次测试,修改视频和音频比特率 OBS设置 阿里云监控 Ngin ...

  10. js 时间格式化 代码

    Date.prototype.Format = function (fmt) { //author: meizz              var o = {                 &quo ...