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. 新人补钙系列教程之:AS3 与 PHP 简单通信基础

    package { import flash.display.Loader; import flash.events.Event; import flash.net.URLLoader; import ...

  2. 用PHP上传文件时$_FILES中error返回值详解

    用PHP上传文件时,我们会用程序去监听浏览器发送过来的文件信息,首先会通 过$_FILES[fieldName]['error']的不同数值来判断此欲上传的文件状态是否正常.$_FILES[field ...

  3. Troubles in Building Android Source Code

    Some Troubles or problems you may encounter while you setup the Android source code build environmen ...

  4. 初步了解更新锁(U)与排它锁(X)

     一直没有认真了解UPDATE操作的锁.近期在MSDN论坛上看到一个问题,询问堆表更新的死锁问题,问题非常easy,有相似这种表及数据: CREATE TABLE dbo.tb( c1 int, ...

  5. Java 实现模板方法(TemplateMethod)模式

    类图 /** * 业务流程模板.提供基本框架 * @author stone * */ public abstract class BaseTemplate { public abstract voi ...

  6. shell 重定向输入

    #!/bin/bash NC_START="nc 192.168.76.227 9999" LOOP= ;i<$LOOP;i++)) do $NC_START << ...

  7. TFS 设置(转)

    一 参考以下两个链接进行相关软件的安装和用户权限配置: http://www.cnblogs.com/WilsonWu/archive/2011/11/24/2261674.html http://w ...

  8. <<= 什么意思?|=什么意思?

    <<= 什么意思?|=什么意思?   x <<= 2; // x = x << 2; y |= 8; // y = y | 8;   这些都是被缩写了!位运算-- ...

  9. JavaScript对象按值传递

    1.示例 <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF- ...

  10. uva 10034 Freckles (kruskal||prim)

    题目上仅仅给的坐标,没有给出来边的长度,不管是prim算法还是kruskal算法我们都须要知道边的长度来操作. 这道题是浮点数,也没啥大的差别,处理一下就能够了. 有关这两个算法的介绍前面我已经写过了 ...