ACboy needs your help

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5872    Accepted Submission(s): 3196

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
 
分组背包,背包容量m,物品分为n组,每组只能取一件,求背包最大价值。
dp[i][j]表示对于前i组物品,背包容量为j时的最大价值,此时对于每种dp[i][j]需要遍历第i组的每一个物品,求出最大的dp[i][j];
 
状态转移方程:
          dp[i][j]=max(dp[i][j],dp[i-1][j-k]+ma[i][k])
 
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
#define Max 105
int dp[Max][Max],ma[Max][Max];
int n,m;
int main()
{
int i,j;
memset(ma,,sizeof(ma));
freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m))
{
if(n==&&m==)
break;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&ma[i][j]);
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
for(int k=;k<=j;k++)
{
if(dp[i][j]<dp[i-][j-k]+ma[i][k])
dp[i][j]=dp[i-][j-k]+ma[i][k];
}
//cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
printf("%d\n",dp[n][m]);
}
return ;
}
 

ACboy needs your help(HDU 1712 分组背包入门)的更多相关文章

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

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

  2. HDU 1712 分组背包

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

  3. ACboy needs your help HDU - 1712

    ACboy needs your help HDU - 1712 ans[i][j]表示前i门课共花j时间最大收益.对于第i门课,可以花k(0<=k<=j)时间,那么之前i-1门课共花j- ...

  4. P1757 通天之分组背包 / hdu1712 ACboy needs your help (分组背包入门)

    P1757 通天之分组背包 hdu1712 ACboy needs your help hdu1712题意:A[i][j]表示用j天学习第i个课程能够得到A[i][j]的收益,求m天内获得的收益最大值 ...

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

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

  6. HDU 4341 分组背包

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

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

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

  8. HDU 1712 ACboy needs your help 典型的分组背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 ACboy needs your help Time Limit: 1000/1000 MS ( ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=1712 题意: 有个人学习n门课程,a[i][j]表示用j分钟学习第i门课程所能获得的价值,背包容量为一共有m时间 ...

随机推荐

  1. Android ndk第一步,构建jni headers

    转载请注明出处:http://www.cnblogs.com/fpzeng/p/4281801.html 源码请见 https://github.com/fpzeng/HelloJNI PC系统: u ...

  2. NET SignalR 与 LayIM2.0

    ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(五) 之 加好友,加群流程,消息管理和即时消息提示的实现   前言 前前一篇留了个小问题,在上一篇中忘了写了,就是关于L ...

  3. JTA

    http://blog.csdn.net/hengyunabc/article/details/19433947

  4. Windows脚本 - %~dp0的含义

    含义是:更改当前目录为批处理本身的目录,有些晕吧?不急,我举例 比如你有个批处理a.bat在D:\qq文件夹下  a.bat内容为 cd /d %~dp0 在这里,cd /d %~dp0的意思就是cd ...

  5. 构建WDK驱动出现fatal error U1087: cannot have : and :: dependents for same target

    原因:WDK在编译驱动时,是不允许源文件所在的路径(全路径)中包含空格的,如果你包含了空格,就会出现上述错误. 解决方法:把源文件放在一个没有空格的路径下. reference: http://blo ...

  6. linux sar查看网络流量

    sar -n DEV 1 10 -n { keyword [,...] | ALL } Report network statistics. IFACE Name of the network int ...

  7. c语言sizeof与strlen的区别

    #include <stdio.h> #include <stdlib.h> #include <string.h> //strlen与sizeof的区别 //st ...

  8. Java中的enum

    package com.st.java; /** * ENUM枚举类型的使用 * @author Administrator * 2016年04月10日 */ public enum MoneyTyp ...

  9. alert 在手机浏览器会显示网址,怎么能去掉这个网址

    之前就看到有人发过这帖子,现在自己也遇到这问题了. 目前想到的一个解决方案,是用jquery的模拟的alert插件进行代替,可是找的几个插件都不能实现alert的阻塞功能.怎么破 ,具体解决方案如下: ...

  10. 【css3+JavaScript】:一个优雅的对话框

    实现效果: 演示地址:http://codepen.io/anon/pen/BNjYrR ======2015/5/11====== 优化滚动条(scroll):默认的滚动条太丑,忍不住优化下 ::- ...