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. 探讨 : Host在IIS上的WCF Service的执行方式

    一个WCF请求由两个线程来完成 运行在IIS上的WCF service, 你可能会注意到一个比较有趣的现象. 当WCF service接收到一个请求时, 这个请求实际上会有两个线程在执行这个请求. 一 ...

  2. 转--htaccess语法教程 apache服务器伪静态规则教程

    转自:http://blog.csdn.net/qingli518/article/details/9118361 htaccess语法教程apache服务器伪静态规则教程 注:如果你是为了找Disc ...

  3. linux history 命令详解

    linux history 命令详解 显示命令执行时间 linux shell 具有history 功能,即会记录已经执行过的命令,但是默认是不显示命令的执行时间,命令的执行时间,history 已经 ...

  4. 超级强悍的PHP代码编辑器PHPstorm及配置

    如何下载安装 官方网站:http://www.jetbrains.com/phpstorm/,本篇文章展示的是5.0版本以,所以,如果你的软件版本过高,可能可有误,所以,如果有问题,请在本站留言,做为 ...

  5. Extjs4.2 Tree使用技巧

    Extjs4.2 Tree使用技巧小结demo 本案例使用了Ext.Tree.Panel的如下知识点: 1.刷新.重新加载Tree,定位到上次的节点位置 2.Tree的右键操作 3.Extjs4.x ...

  6. CENTOS下Python 升级后YUM无法使用的解决办法

    Python有很多实用的工具,安装依赖python版本较高,升级Python后导致yum无法使用. 原因: 系统自带的yum依赖Python老版本,升级后不兼容 解决办法: 1. 列出所有版本,确定老 ...

  7. 1.C#基础学习笔记3---C#字符串(转义符和内存存储无关)

    技术qq交流群:JavaDream:251572072  教程下载,在线交流:创梦IT社区:www.credream.com ------------------------------------- ...

  8. [置顶] 和孩子们一起学Python编程

    1. 推荐书名 Computer Programming for Kids and Other Beginners in Python, 4Ed.pdf     中文译名:<和孩子们一起学Pyt ...

  9. Nodejs --我自己的学习笔记

    对于Nodejs,相信客官并不陌生,网上却已众说纷纭,有人说是一个平台,有人说是服务器JavaScript,有人说一个框架… 之前亦有过研究,多怀可远观而不可亵玩也.高效率,I/O操作,异步编程,以及 ...

  10. 009-程序集路径Web窗体

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs& ...