*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\)虽然以前考的次 ...
随机推荐
- HDU 3364 Lanterns 高斯消元
Lanterns Problem Description Alice has received a beautiful present from Bob. The present contains ...
- HDU 5869 Different GCD Subarray Query 离线+树状数组
Different GCD Subarray Query Problem Description This is a simple problem. The teacher gives Bob a ...
- Codeforces Round #161 (Div. 2) D. Cycle in Graph(无向图中找指定长度的简单环)
题目链接:http://codeforces.com/problemset/problem/263/D 思路:一遍dfs即可,dp[u]表示当前遍历到节点u的长度,对于节点u的邻接点v,如果v没有被访 ...
- Nginx日志定时切割脚本
nginx的日志文件如果你不处理,将变得越来越大,我们可以写一个nginx日志切割脚本来自动切割日志文件. 第一步就是重命名日志文件,不用担心重命名后nginx找不到日志文件而丢失日志.在你未重新打开 ...
- BZOJ 2565 回文串-Manacher
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2565 题意:中文题 思路:定义L[i],R[i].表示以i为左端点/右端点时,最长回文串长 ...
- 10324 Global Warming dfs + 二分
时间限制:1000MS 内存限制:65535K提交次数:0 通过次数:0 题型: 编程题 语言: G++;GCC Description Global warming is a big prob ...
- FastMM 定位内存泄露的代码位置
FastMM 定位内存泄露的代码位置 开源的FastMM,使用很简单,在工程的第一行引用FastMM4即可(注意,一定要在第一个Uses的位置),可以在调试程序时提示内存泄露情况,还可以生成报告. 在 ...
- docker push到本地仓库失败
开启registry的方法: docker run -d -p : -v /data/registry:/tmp/registry registry 出错内容: Error: Status tryin ...
- 并查集(删除) UVA 11987 Almost Union-Find
题目传送门 题意:训练指南P246 分析:主要是第二种操作难办,并查集如何支持删除操作?很巧妙的方法:将并查集树上p的影响消除,即在祖先上(sz--, sum -= p),然后为p换上马甲:id[p] ...
- Linux 命令集合
1.find /etc -name "*" | xargs grep "hello abcserver" 按照内容过滤2.grep -v "^#&qu ...