*HDU3496 背包DP
Watch The Movie
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 7397 Accepted Submission(s): 2367
semester is coming, and DuoDuo has to go to school tomorrow. She
decides to have fun tonight and will be very busy after tonight. She
like watch cartoon very much. So she wants her uncle to buy some movies
and watch with her tonight. Her grandfather gave them L minutes to watch
the cartoon. After that they have to go to sleep.
DuoDuo list N
piece of movies from 1 to N. All of them are her favorite, and she wants
her uncle buy for her. She give a value Vi (Vi > 0) of the N piece
of movies. The higher value a movie gets shows that DuoDuo likes it
more. Each movie has a time Ti to play over. If a movie DuoDuo choice to
watch she won’t stop until it goes to end.
But there is a strange
problem, the shop just sell M piece of movies (not less or more then),
It is difficult for her uncle to make the decision. How to select M
piece of movies from N piece of DVDs that DuoDuo want to get the highest
value and the time they cost not more then L.
How clever you are! Please help DuoDuo’s uncle.
first line of the input file contains a single integer t (1 ≤ t ≤ 10),
the number of test cases, followed by input data for each test case:
The first line is: N(N <= 100),M(M<=N),L(L <= 1000)
N: the number of DVD that DuoDuo want buy.
M: the number of DVD that the shop can sale.
L: the longest time that her grandfather allowed to watch.
The
second line to N+1 line, each line contain two numbers. The first
number is the time of the ith DVD, and the second number is the value of
ith DVD that DuoDuo rated.
The total value that DuoDuo can get tonight.
If DuoDuo can’t watch all of the movies that her uncle had bought for her, please output 0.
9 1
//二维费用背包,第一维l不用必须装满,第二维m必须装满,这就要特殊初始化,dp时如果只为负忽略。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int t,n,m,l;
int f[][];
int main()
{
int tim,val;
scanf("%d",&t);
while(t--)
{
memset(f,-,sizeof(f));
scanf("%d%d%d",&n,&m,&l);
for(int i=;i<=l;i++)
f[i][]=; //初始化。
for(int i=;i<=n;i++)
{
scanf("%d%d",&tim,&val);
for(int j=l;j>=tim;j--)
{
for(int k=m;k>=;k--)
{
if(f[j-tim][k-]<) continue; //直为负跳过
f[j][k]=max(f[j][k],f[j-tim][k-]+val);
}
}
}
if(f[l][m]<) printf("0\n");
else printf("%d\n",f[l][m]);
}
return ;
}
*HDU3496 背包DP的更多相关文章
- 背包dp整理
01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...
- hdu 5534 Partial Tree 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- HDU 5501 The Highest Mark 背包dp
The Highest Mark Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp
B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...
- noj [1479] How many (01背包||DP||DFS)
http://ac.nbutoj.com/Problem/view.xhtml?id=1479 [1479] How many 时间限制: 1000 ms 内存限制: 65535 K 问题描述 The ...
- HDU 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- BZOJ 1004: [HNOI2008]Cards( 置换群 + burnside引理 + 背包dp + 乘法逆元 )
题意保证了是一个置换群. 根据burnside引理, 答案为Σc(f) / (M+1). c(f)表示置换f的不动点数, 而题目限制了颜色的数量, 所以还得满足题目, 用背包dp来计算.dp(x,i, ...
- G - Surf Gym - 100819S -逆向背包DP
G - Surf Gym - 100819S 思路 :有点类似 逆向背包DP , 因为这些事件发生后是对后面的时间有影响. 所以,我们 进行逆向DP,具体 见代码实现. #include<bit ...
- 树形DP和状压DP和背包DP
树形DP和状压DP和背包DP 树形\(DP\)和状压\(DP\)虽然在\(NOIp\)中考的不多,但是仍然是一个比较常用的算法,因此学好这两个\(DP\)也是很重要的.而背包\(DP\)虽然以前考的次 ...
随机推荐
- pig的各种运行模式与运行方式详解
一.pig的运行模式: Pig 有两种运行模式: Local 模式和 MapReduce 模式.当 Pig 在 Local 模式运行的时候, Pig 将只访问本地一台主机:当 Pig 在 MapRed ...
- Android和SQLite版本对应关系
Android和SQLite版本对应关系 今天Xamarin群有人问到Android和SQLite版本如何对应,顺手查了一下,贴出来. SQLite 3.8.4.3: • 21-5.0-Lollipo ...
- hdu 4990 Reading comprehension 二分 + 快速幂
Description Read the program below carefully then answer the question. #pragma comment(linker, " ...
- 遍历table指定name的td
$("td[name='rates']").each(function () { var temp = $(this).text().substr(0,$(this).text() ...
- C#生成PDF总结
(一)C#生成PDF总结 (1)iTextSharp控件对iTextSharp研究还可以表格.文字.各种GDI对象,图片,水印,文字旋转(2)aspose的控件(3)PDF Library这个类库(只 ...
- git的合并与推送
集中式合作模式 1.git fetch 获取远程更新 2.git merge origin/master 进行合并,如果报错,则相应解决.注:你得用git bash命令行执行才能看见报错详情,用ecl ...
- Zend studio 10.6 配置XDEBUG
1. 查看PHP版本,下载XDebug 然后去网站http://xdebug.org/download.php下载相应的XDEBUG, 把下载好的文件放到相应的PHP下的EXT目录下,替换之前 ...
- BZOJ2190 & 欧拉函数
题意: 求1-n内互质数对个数 SOL: 裸欧拉函数,还有莫比乌斯反演的加速什么的,挖个坑. Code: /*============================================= ...
- Topcoder SRM 626 DIV2 SumOfPower
本题就是求所有连续子数列的和 开始拿到题目还以为求的时数列子集的和,认真看到题目才知道是连续子数列 循环遍历即可 int findSum(vector <int> array) { ; ; ...
- BZOJ 3211 题解
3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 2549 Solved: 946[Submit][Status][Discus ...