*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 4770(枚举 + dfs爆搜)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4770 思路:由于最多只有15个".",可以直接枚举放置的位置,然后判断是否能够全部 ...
- poj 3895(求无向图的最大简单环)
题目链接:http://poj.org/problem?id=3895 思想很简单,就是dfs,并且用一个数组记录到该节点所走过的长度,然后如果遇到已经走过的,就说明存在环了, 更新一下ans. /* ...
- Linux学习笔记(10)文本编辑器vim
vim是一个功能强大的全屏幕文本编辑器,是Linux/Unix最常用的文本编辑器,其作用是建立.编辑.显示文本文件.vim的特点是没有菜单,只有命令. vim主要有三种工作模式,分别为命令模式.插入模 ...
- Zookeeper 初体验之——伪分布式安装(转)
原文地址: http://blog.csdn.net/salonzhou/article/details/47401069 简介 Apache Zookeeper 是由 Apache Hadoop 的 ...
- LoadRunner 事务函数
status 包括LR_PASS, LR_FAIL, LR_AUTO, LR_STOP(这个没用过) lr_set_transaction_instance_status(status); 可以根 ...
- JMeter参数化(一)
JMeter参数化的4种方法:
- Loadrunner中参数化实战(8)-Unique+Each occurrence
参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Unique+Each occurrence 设置迭代4次Action 结果如下:
- wpf,记录一下颜色设置的2中方法,,,
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color ...
- BZOJ4699 : 树上的最短路
这道题主要是要解决以下两个问题: 问题1: 给定一个点$x$,如何取出所有经过它的下水道? 一条下水道经过$x$等价于它起点在$x$的子树里面且终点不在$x$的子树里面,或者两端点的lca就是$x$. ...
- BZOJ4367 : [IOI2014]holiday假期
设 $fl[i]$表示从$S$向左走,用了不超过$i$天且不回头的最大收益. $fr[i]$表示从$S$向右走,用了不超过$i$天且不回头的最大收益. $gl[i]$表示从$S$向左走,用了不超过$i ...