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. django静态html中做动态变化

    在搭建网站中经常有筛选分类的需求 在django中为了简便,我们经常将某些相同部分的内容取出来单独存放形成一个base模板,其他的template继承这个base就可以使用其中的内容 但是这些相同的部 ...

  2. as well as

    一.as well 用法: 1.as well常用作状语,作“又:也”解,相当于too或also,常位于句末,无须用逗号与句子分开.如: I am going to London and my sis ...

  3. jar文件的Eclipse插件安装

    以[zigen.plugin.db_1.2.2.v20101009.jar]为例. (1)在[\eclipse\dropins]目录下新建一个目录,例如[myplugin] (2)上面新建的n目录下建 ...

  4. 转 : SQL Server数据库优化经验总结

    优化数据库的注意事项: 1.关键字段建立索引. 2.使用存储过程,它使SQL变得更加灵活和高效. 3.备份数据库和清除垃圾数据. 4.SQL语句语法的优化.(可以用Sybase的SQL Expert, ...

  5. mysql导出查询结果到文档

    其实挺简单,就一个命令 select * from my_table into outfile '/tmp/abc.xls'; 然后就是ftp把文件弄回本地了.我的是程序自动放到C:\下   另外,还 ...

  6. 修改pip源为国内网站

    import os,sys,platformini="""[global]index-url = https://pypi.doubanio.com/simple/[in ...

  7. mongoDB: cursor not found on server

    查询mongoDB集合数据更新,数据有400w多.我一次用cursor(游标)取1w,处理更新.程序在某段时间运行中遍历游标时发生异常! DBCursor cursor = tabColl.find( ...

  8. java swing内嵌浏览器,隐藏滚动条

    1 通过定义css样式表来解决 1 html{overflow-y:scoll;overflow:-moz-scrollbars-vertical;} 2 body{width:680px;heigh ...

  9. 转 拉姆达表达式,委托、匿名方法、Lambda表达式的演进

    总结:Lambda表达式的语法:(参数列表=>执行语句) 无参数格式 :()=>{执行语句} 有参数格式:x=> x % 2 == 0 1.假设给我们一个泛型对象List<T& ...

  10. Python---copy()、deepcopy()与赋值的区别

    copy()与deepcopy()之间的主要区别是python对数据的存储方式. 首先直接上结论: —–深复制,即将被复制对象完全再复制一遍作为独立的新个体单独存在.所以改变原有被复制对象不会对已经复 ...