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. Emacs助力PowerShell

    Emacs助力PowerShell 阅读目录 1 下载安装Emacs windows版本 2 下载el文件和配置Emacs加载PowerShell 3 体验用Emacs来执行和编辑PowerShell ...

  2. Modern 阅读笔记 一 PSR标准

    一.标准 PSR php standards Recommendation PHP 推荐标准 PSR-1 基本代码风格 PSR-2 严格的代码风格  PSR-3 日志记录器接口 PSR-4 自动加载  ...

  3. 从UI开始

    虚拟化平台cloudstack(8)——从UI开始   UI ucloudstack采用的是前后端分离的架构,就是说前端可以选择使用web.swing甚至其它的界面,都可以. 我们来看cloudsta ...

  4. javascript计算字符串中出现最多的字符和个数

    代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <t ...

  5. Mac下chrome的webapp hostadmin 快速切换host

    首先是安装 app ,https://chrome.google.com/webstore/detail/hostadmin-app/mfoaclfeiefiehgaojbmncmefhdnikeg ...

  6. .Net项目框架

    摘要:本文描述了在用VS.NET进行B/S开发时采用的框架结构,一般建立类库项目和Web项目,在Web基本aspx页面类中调用类库中方法,同时在aspx页面类中不需要写任何对数据库操作的SQL代码,便 ...

  7. uploadify的使用

    uploadify的使用 课程设计需要实现上传文件模块,本来ASP.NET是有内置的控件,但是ASP.NET MVC没有,所以就有两种方法:自定义和采用第三方插件.由于时间的关系,故采用第三方插件:u ...

  8. c# 项目带皮肤一起打包发布解决办法

    c# 项目带皮肤一起打包发布解决办法 前提:c#语言   winform应用程序  皮肤为IrisSkin2 目标:在打包发布独立应用 程序时,将皮肤也一起打包发布,实现程序在其它机子安装时,皮肤效果 ...

  9. asp.net MVC 路由机制

    1:ASP.NET的路由机制主要有两种用途: -->1:匹配请求的Url,将这些请求映射到控制器 -->2:选择一个匹配的路由,构造出一个Url 2:ASP.NET路由机制与URL重写的区 ...

  10. CMake学习

    CMake学习 本篇分享一下有关CMake的一些学习心得以及相关使用. 作者:AlphaGL.版权所有,欢迎保留原文链接进行转载 :) 本文目录如下: 1.CMake介绍 2.CMake安装与使用 2 ...