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

题意:  有n个课程,m天时间,接下来n*m的矩阵表示该课程花费1~m天时间所获能得的价值,求花费m天时间能获得的最大价值
   背包:
       分组背包模板题..将每一天看成一个组,每组只能选一个。

代码实现:

  #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n,m,i,j,k,a[][],dp[];
while(cin>>n>>m&&n&&m)
{
for(i=;i<=n;i++)
for(j=;j<=m;j++)
cin>>a[i][j];
memset(dp,,sizeof(dp));
for(i=;i<=n;i++)//分组
for(j=m;j>;j--)//容量
for(k=;k<=j;k++)//第i组数据
dp[j]=max(dp[j],dp[j-k]+a[i][k]);
cout<<dp[m]<<endl;
}
return ;
}

ACboy needs your help hdu 分组背包问题的更多相关文章

  1. HDU - 1712 - ACboy needs your help 【分组背包】

    <题目链接> 题目大意:有n个课程,现在花M天来学习这些课程,学习每个课程花的天数所得到的价值不同,求M天怎么分配学习才能得到的价值最大.(这些课程得到的价值和所花天数的关系由矩阵给出) ...

  2. 动态规划:HDU1712-ACboy needs your help(分组背包问题)

    ACboy needs your help Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Othe ...

  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. HDU 1712 ACboy needs your help(分组背包入门题)

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

  5. HDU 1712 ACboy needs your help(分组背包)

    题意:给你n的课程组,每个课程组有m个课程,每个课程有一个完成时间与价值.问在m天内每组课程组最多选择一个,这样可以得到的最大价值是多少 题解:分组背包,其实就是每个课程组进行01背包,再在课程组内部 ...

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

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

  7. HDU1712:ACboy needs your help(分组背包)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1712 解释看这里:http://www.cnblogs.com/zhangmingcheng/p/3940 ...

  8. 【HDU1712】ACboy needs your help(分组背包)

    将背包九讲往后看了看,学习了一下分组背包.来做几道入门题,试试手. #include <iostream> #include <cstring> #include <cs ...

  9. 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 ...

随机推荐

  1. Jquery文本框值改变事件兼容性

    Jquery文本框值改变事件(支持火狐.ie)   Jquery值改变事件支持火狐和ie浏览器,并且测试通过,绑定后台代码可以做成autocomplete控件. 具体代码列举如下: ? $(docum ...

  2. android 4.2 源码在64位Ubuntu编译

    1.获取Android源代码 Android官网给出了从网上下载源代码的方法,具体流程如下网址所示:http://source.android.com/source/downloading.html ...

  3. Spring整合Hibernate笔记

    1. Spring 指定datasource a) 参考文档,找dbcp.BasicDataSource i. c3p0 ii. dbcp <bean id="dataSource&q ...

  4. hadoop集群安装

    首现非常感谢 虾皮(http://www.cnblogs.com/xia520pi/archive/2012/05/16/2503949.html) 安装过程是参照他的<Hadoop集群(第5期 ...

  5. [每日一题] OCP1z0-047 :2013-07-26 alter table set unused之后各种情况处理

    有疑问可以去itpub讨论:http://www.itpub.net/thread-1804872-1-1.html 对于alter table setunused的用法,查官方文档: alter_t ...

  6. EF-Code First(5):二级缓存

    EF-Code First(5):二级缓存 〇.目录 一.前言 二.缓存设计 (一) 引用EFProviderWrappers (二) 缓存代码分析及整合 1. 关键代码简介 2. 应用缓存扩展 三. ...

  7. 37条常用Linux Shell命令组合

    序号 任务 命令组合 1 删除0字节文件 find . -type f -size 0 -exec rm -rf {} \; find . type f -size 0 -delete 2 查看进程, ...

  8. PHP使用DomDocument抓取HTML内容

    有时候会有需要从一个HTML页面来分离出你需要的一些数据来进行处理. 当然自己分析文件肯定可以,但是比较快速且方便的是使用正则表达式或者DOM. 鉴于正则表达式我不熟悉,所以我打算使用DOM来完成. ...

  9. Coding the Matrix作业Python Lab及提交方法

    Coding the Matrix: Linear Algebra through Computer Science Applications 这是一门用python实现矩阵运算的课,第一次作业就感觉 ...

  10. Swift3集成极光推送

      现在很多程序都开始使用Swift开发了,但是第三方库大多数都是用OC写的,所以我们要使用Swift和OC混编.今天的内容主要讲Swift3.0集成极光推送. 1.准备工作   集成指南,极光上说的 ...