HDU 1712

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 个课程,m 天学习,然后 n 行,每行 m 个数,i 行 j 列代表第 i 课程花费 j 天可以获得的价值。问 m 天可以获得得最大价值
dp[i][j] 代表 i 种书,花费 j 天可以获得的最大价值
dp[i][j] = dp[i-1][j] + max (A[i][k])    0<=k<=j 
 #include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
#define MX 105
int n,m;
int dp[MX][MX];
int A[MX][MX];
int main()
{
while (scanf("%d%d",&n,&m)&&(n||m))
{
memset(dp,,sizeof(dp));
memset(A,,sizeof(A));
for (int i=;i<=n;i++)
{
for (int j=;j<=m;j++)
scanf("%d",&A[i][j]);
}
for (int i=;i<=n;i++) // i 本书
{
for (int j=;j<=m;j++) // j 天
{
for (int k=;k<=j;k++)
{
dp[i][j]=max(A[i][k]+dp[i-][j-k],dp[i][j]);
}
}
}
printf("%d\n",dp[n][m]);
}
return ;
}

ACboy needs your help(简单DP)的更多相关文章

  1. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  3. codeforces Gym 100500H A. Potion of Immortality 简单DP

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  4. 简单dp --- HDU1248寒冰王座

    题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...

  5. poj2385 简单DP

    J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit ...

  6. hdu1087 简单DP

    I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     ...

  7. poj 1157 LITTLE SHOP_简单dp

    题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...

  8. hdu 2471 简单DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=(  dp[n-1][m],dp[n][m-1],d[i][k ...

  9. Codeforces 41D Pawn 简单dp

    题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...

随机推荐

  1. ios开发中APP底部上滑不能调出如WiFi、蓝牙、播放等的设置页面的解决的方法

    在开发的APP中我们通常通过手动底部上滑来调出WiFi.蓝牙.飞行模式等的设置页面.有时我们开发的APP无法调出. 解决的方法: 进入iPhone "设置" --> &quo ...

  2. Spring MVC 解读——<mvc:annotation-driven/>

    Spring MVC 解读——<mvc:annotation-driven/> 一.AnnotationDrivenBeanDefinitionParser 通常如果我们希望通过注解的方式 ...

  3. 通过脚本发送zabbix微信报警

    实现zabbix通过微信报警的方式也是通过脚本来实现,与邮件报警不同的是,脚本调用的微信的相关接口的获取相对复杂一点 1.申请一个微信公众号(企业号) 申请方法不多说,如果已申请请忽略 2.在微信企业 ...

  4. MyEclipse导入Hibernate出现Path must include project and resource;/project name

    如图,在MyEclipse 2014以下版本中都没遇见这个问题. 在导入Hibernate框架的时候,可以说真的随缘,运气不好,明明配置全都没问题,还是连续几次失败,这个时候除了烧高香拜拜,也只能靠百 ...

  5. 迭代器适配器(二)general inserter的实现

    上节我们实现了back_inserter和front_inserter,接下来是更为普通的插入迭代器,它允许用户指定插入位置. 实现代码如下: #ifndef ITERATOR_HPP #define ...

  6. DeleteDC、ReleaseDC 、DeleteObject的使用

    DeleteDC 该函数删除指定的设备上下文环境(DC). 原型: BOOL DeleteDC(HDC hdc): 参数: hdc:设备上下文环境的句柄. 返回值: 成功,返回非零值:失败,返回零.调 ...

  7. DPM(Deformable Part Model)原理详解(汇总)

    写在前面: DPM(Deformable Part Model),正如其名称所述,可变形的组件模型,是一种基于组件的检测算法,其所见即其意.该模型由大神Felzenszwalb在2008年提出,并发表 ...

  8. UITextView被键盘遮挡的处理

    这个应该是一个通用的任务了吧,键盘弹出来的时候,UITextView(或者UITextField)会被遮挡. 解决的办法就不是很能通用了. 1. 如果有UIScrollView做父view的话只需要滚 ...

  9. Devops成功的八大炫酷工具

    原文链接:http://www.infoworld.com/article/3031009/devops/8-more-cool-tools-for-devops-success.html 为自动化和 ...

  10. windows和linux下目录分隔符兼容问题(换行回车兼容)

    windows和linux下目录分隔符兼容 DIRECTORY_SEPARATOR 换行回车兼容 PHP_EOF