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. OpenGL帧缓存对象(FBO:Frame Buffer Object) 【转】

    http://blog.csdn.net/dreamcs/article/details/7691690 原文地址http://www.songho.ca/opengl/gl_fbo.html 但有改 ...

  2. HIVE 不支持group by 别名

    hive不支持group by 别名,如果需要group by 别名的情况,可以使用 别名的 值作为group by 的值

  3. 2017.4.18 linux中执行某文件提示权限不够

    因为没有对start.sh文件的执行权限,所以提示权限不够. 加一个执行权限: chmod +x start.sh 可以看到,执行权限已经有了.此时再执行,就ok了.  

  4. 测试用例 自动生成工具PICT与AllPairs

    通常我们在设计或编写测试用例时,存在一个"痛点":要么设计的测试用例存在遗漏,难以100%覆盖测试需求:要么被测系统过于复杂,设计的测试用例过多,导致前期的设计和后续的执行工作量过 ...

  5. mysql double 乘法 缺失精度

    CREATE TABLE tmp_decimal( id BIGINT auto_increment PRIMARY KEY , amount DOUBLE ); 创建测试表 插入测试数据 INSER ...

  6. python——SyntaxError:invalid syntax

    格式不对,tab 或空格的格式不统一导致

  7. STL学习笔记(迭代器配接器)

    Reverse(逆向)迭代器 Reverse迭代器是一种配接器. 重新定义递增运算和递减运算.使其行为正好倒置. 如果你使用这类迭代器,算法将以逆向次序处理元素.所有标准容器都允许使用Reverse迭 ...

  8. [ACM] HDU 5078 Osu!

    Osu! Problem Description Osu! is a very popular music game. Basically, it is a game about clicking. ...

  9. Input 银行卡验证

    $("#card_num").keyup(function(){ var op=""; var t=$("#card_num").val() ...

  10. 【已解决】ckfinder_php_3.4.4 IIS 报错 无效请求

    ckfinder_php_3.4.4 IIS 报错 无效请求 (Invalid request) Apache 正常,但是在IIS环境下报错,解决方法 设置 C:\Windows\Temp 目录 给 ...