ACboy needs your help

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

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
 
题意:N个任务M天完成,每个任务花费每天都有一定的收益,问收益最大
分析:分组背包
把N个任务看成N组,其中每组中只能选择一个,也就是每一个任务花费的天数肯定是一个数,然后花费的天数还有费用,分组背包纯裸模板
http://www.cppblog.com/Onway/archive/2010/08/09/122695.html这个讲讲解了第二重和三重循环的设计思路
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX = ;
int n,m;
int dp[MAX],a[MAX][MAX];
int main()
{
while(scanf("%d%d", &n, &m) != EOF)
{
if(n == && m == )
break;
for(int i = ; i <= n; i++)
for(int j = ; j <= m; j++)
scanf("%d", &a[i][j]);
memset(dp, , sizeof(dp));
for(int i = ; i <= n; i++)
{
for(int j = m; j > ; j--)
{
for(int k = ; k <=m; k++)
{
if(j >= k)
dp[j] = max(dp[j], dp[j - k] + a[i][k]);
}
}
}
printf("%d\n", dp[m]);
}
return ;
}
 

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

  1. hdu4003详解(树形dp+多组背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4003 Find Metal Mineral Time Limit: 2000/1000 MS (Jav ...

  2. dp--分组背包 P1757 通天之分组背包

    题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品相互冲突,现在,他想知道最大 ...

  3. ACboy needs your help-分组背包模板题

    id=17676" target="_blank" style="color:blue; text-decoration:none">ACboy ...

  4. D - 英文题 (多组背包)

    The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a gian ...

  5. HDU 3449 Consumer (背包问题之有依赖背包)

    题目链接 Problem Description FJ is going to do some shopping, and before that, he needs some boxes to ca ...

  6. 【题解】洛谷P1273 有线电视网(树上分组背包)

    次元传送门:洛谷P1273 思路 一开始想的是普通树形DP 但是好像实现不大好 观摩了一下题解 是树上分组背包 设f[i][j]为以i为根的子树中取j个客户得到的总价值 我们可以以i为根有j组 在每一 ...

  7. (第三场) A PACM Team 【dp,五维背包】

    链接:https://www.nowcoder.com/acm/contest/141/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  8. hdu 3535 背包综合题

    /* 有n组背包,每组都有限制 0.至少选一项 1.最多选一项 2.任意选 */ #include <iostream> #include <cstdio> #include ...

  9. HDU3535 AreYouBusy 混合背包

    题目大意 给出几组物品的体积和价值,每组分为三种:0.组内物品至少选一个:1.组内物品最多选一个:2.组内物品任意选.给出背包容量,求所能得到的最大价值. 注意 仔细审题,把样例好好看完了再答题,否则 ...

随机推荐

  1. Node.js之事件events

    Events a.EventEmitter支持多个事件监听,最大为10,也可以自定义最大数 //添加监听var EventEmitter = require('events').EventEmitte ...

  2. 对EBS中配置文件的初步认识

    配置文件(PROFILE)在EBS系统配置占有很重要的位置,功能顾问要对很多重要的配置文件做到非常熟悉才行.否则出现一个问题,可能在郁闷许久后,发觉只是某个不起眼的配置文件在捣乱.配置文件相当于带有权 ...

  3. JQuery 如何选择带有多个class的元素

    Q: 比如下面代码需要选择同时带有这几个class的元素,怎么写? 1 <div class="modal fade in"></div> A: 1. 依次 ...

  4. C#基础——谈谈.NET异步编程的演变史

    http://www.cnblogs.com/fzrain/p/3545810.html 前言 C#5.0最重要的改进,就是提供了更强大的异步编程.C#5.0仅增加两个新的关键字:async和awai ...

  5. CSS 实现加载动画之五-光盘旋转

    今天做的这个动画叫光盘旋转,名字自己取的.动画的效果估计很多人都很熟悉,就是微信朋友圈里的加载动画.做过前面几个动画,发现其实都一个原理,就是如何将动画的元素如何分离出来.这个动画的实现也很简单,关键 ...

  6. 在matlab和opencv中分别实现稀疏表示

    在本文中,稀疏表示的原理不再具体讲解,有需要的同学请自行百度. 本文采用OMP算法来求解稀疏系数.首先随机生成字典数据和待测试数据 字典数据: dic =[ 6, 7, 9, 9, 7, 0, 6, ...

  7. LeetCode:Construct Binary Tree from Inorder and Postorder Traversal,Construct Binary Tree from Preorder and Inorder Traversal

    LeetCode:Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder trav ...

  8. 20145222黄亚奇《Java程序设计》第4周学习总结

    教材学习内容总结 第6章 为了避免重复的行为定义使用继承. 要学会如何正确判断使用继承的时机以及继承之后如何活用多态. 继承的好处之一,就是若你要将name.lexel.blood改为其他名称,那就只 ...

  9. JSTL(JSP Standard Tag Library)读书笔记

    分类                                       Preifx                                          范例 核心标签库--- ...

  10. 微信支付开发-Senparc.Weixin.MP详解

    年底了,反而工作更忙了,我从15年11月开始写<1024伐木累>系列小说和爆笑对白,得到了很多身边的技术好友的支持,现在爆笑对白已经有越来越多的朋友一起帮着写段子,整理,包括小说内容的编辑 ...