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天,在输入n*m的矩阵,分别代表经历j天在i课程上,得到的一个权值,求大的权值。
#include <iostream>
#include <cstring>
using namespace std;
int a[][],dp[];
int n,m;
int main()
{
while(cin>>n>>m,n||m)
{
memset(dp,,sizeof dp);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
cin>>a[i][j];
for(int i=;i<=n;i++)
for(int j=m;j>=;j--)
for(int k=;k<=j;k++)///枚举在i课程的天数
dp[j]=max(dp[j],dp[j-k]+a[i][k]);
cout<<dp[m]<<'\n';
}
return ;
}

 

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

  1. HDU1712:ACboy needs your help(分组背包模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem Description ACboy has N courses this term, an ...

  2. hdu1712 ACboy needs your help 分组背包

    最基础的分组背包~ #include <iostream> #include <cstdio> #include <cstdlib> #include <cs ...

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

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

  4. [hdu1712]ACboy needs your help分组背包

    题意:一共$m$天,$n$门课程,每门课程花费$i$天得到$j$的价值,求最后获得的最大价值 解题关键:分组背包练习,注意循环的顺序不能颠倒 伪代码: $for$ 所有的组$k$   $for{\rm ...

  5. hdu 1712 ACboy needs your help 分组背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem ...

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

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

  7. B - ACboy needs your help(动态规划,分组背包)

    B - ACboy needs your help Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

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

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

  9. 分组背包 例题:hdu 1712 ACboy needs your help

    分组背包需求 有N件物品,告诉你这N件物品的重量以及价值,将这些物品划分为K组,每组中的物品互相冲突,最多选一件,求解将哪些物品装入背包可使这些物品的费用综合不超过背包的容量,且价值总和最大. 解题模 ...

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

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

随机推荐

  1. Win7系统出现提示: “Windows已遇到关键问题,将在一分钟后自动重新启动。”

    1. 若用户在使用Win7系统时,遇到上述系统故障,建议重启电脑.等电脑开机自检一过,马上按键盘上的F8键,选择进入安全模式.在安全模式下,进行系统还原.其他的解决方法见下. 1.或者,在安全模式下, ...

  2. KEIL软件仿真死在等待外部晶振起振

    这是由于是Debug里面的设置有问题 主要是下面2项设置 Dialog DLL默认是DCM3.DLL Parameter默认是-pCM3 应改为 Dialog DLL默认是DARMSTM.DLL Pa ...

  3. RHEL6.5---LVS(IP-TUN)

    实验环境: 主机名 IP  所需软件 master eth0==>192.168.30.160(RIP) eth0:1==>192.168.30.130(VIP) ipvsadm node ...

  4. Java URL 中文乱码解决办法

    一. 统一所有的编码格式 (1)JSP页面设置:<%@ page language="java" import="java.util.*" pageEnc ...

  5. Django创建第一个应用

    一.创建第一个应用,并在settings.py中添加. python manage.py startapp article 二.创建第一个模型 class Article(models.Model): ...

  6. MongoDB最简单的入门教程之五-通过Restful API访问MongoDB

    通过前面四篇的学习,我们已经在本地安装了一个MongoDB数据库,并且通过一个简单的Spring boot应用的单元测试,插入了几条记录到MongoDB中,并通过MongoDB Compass查看到了 ...

  7. 原创:四种Linux系统开机启动项优命令超给力超详细详解

    老葵花哥哥又开课了 接下来是你们的齐天大圣孙悟空给你们带来的详细版Linux系统开机启动优化四种命令 第一种方法是很正常的 第二种有点难理解 第三种来自我的一个奇思妙想 本文档秉承 不要钱也不要臀部的 ...

  8. 指针-动态开点&合并线段树

    一个知识点不在一道题里说是没有灵魂的 线段树是用来处理区间信息的咯 但是往往因为需要4倍空间让许多人退却,而动态开点的线段树就非常棒 仿佛只用2倍就可以咯 指针保存位置,即节点信息,是很舒适的,所以用 ...

  9. iview 的 Carousel 走马灯 焦点图 不能用 建议换/vue-awesome-swiper

    https://www.npmjs.com/package/vue-awesome-swiper

  10. Spread / Rest 操作符

    Spread / Rest 操作符指的是 ...,具体是 Spread 还是 Rest 需要看上下文语境. 当被用于迭代器中时,它是一个 Spread 操作符:(参数为数组) function foo ...