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

Problem Description
New
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.
 
Input
The
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.
 
Output
Contain one number. (It is less then 2^31.)
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.
 
Sample Input
1
3 2 10
11 100 1
2
9 1
 
Sample Output
3
 
Source
 
题意:
买电影,每一个电影有他的时长,价值,给出n个可以买的电影,只能从中买m个,并且电影的时长不超过l,问能够买到的最大价值。
代码:
 //二维费用背包,第一维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的更多相关文章

  1. 背包dp整理

    01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...

  2. hdu 5534 Partial Tree 背包DP

    Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  3. 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 ...

  4. 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/ ...

  5. noj [1479] How many (01背包||DP||DFS)

    http://ac.nbutoj.com/Problem/view.xhtml?id=1479 [1479] How many 时间限制: 1000 ms 内存限制: 65535 K 问题描述 The ...

  6. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  7. BZOJ 1004: [HNOI2008]Cards( 置换群 + burnside引理 + 背包dp + 乘法逆元 )

    题意保证了是一个置换群. 根据burnside引理, 答案为Σc(f) / (M+1). c(f)表示置换f的不动点数, 而题目限制了颜色的数量, 所以还得满足题目, 用背包dp来计算.dp(x,i, ...

  8. G - Surf Gym - 100819S -逆向背包DP

    G - Surf Gym - 100819S 思路 :有点类似 逆向背包DP , 因为这些事件发生后是对后面的时间有影响. 所以,我们 进行逆向DP,具体 见代码实现. #include<bit ...

  9. 树形DP和状压DP和背包DP

    树形DP和状压DP和背包DP 树形\(DP\)和状压\(DP\)虽然在\(NOIp\)中考的不多,但是仍然是一个比较常用的算法,因此学好这两个\(DP\)也是很重要的.而背包\(DP\)虽然以前考的次 ...

随机推荐

  1. loj 1316(spfa预处理+状压dp)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27024 题意:求0-(n-1)的经过最多的标记的点的最短路. 思路 ...

  2. Linux C编程(1) vim及gcc命令

    1. 输入以下命令可以启动vi:      (1) vi:不指定文件名,在保存文件时需要指定文件名.      (2) vi 文件名:该文件既可以是已存在的,也可以是新建的.      (3) vi ...

  3. shell-bash学习02运算、拼接、重定向

    运算 let操作 可以直接执行基本的算术操作;使用时,变量名之前不需要再添加$; #!/bin/bash no1=4; no2=5; let result=no1+no2 echo $result 自 ...

  4. git 基础使用

    1: 安装客户端 2: 注册使用github 3: 具体操作 3-1: 右键打开:git bash here 执行 ssh-keygen -t rsa -C "youremail@examp ...

  5. .Net Mvc3框架调用服务端控件解决方案

      /*BY:Wangyexin date:2011年4月30日 20:17:38*/ /*说明:.net mvc3框架,View层调用服务端控件,输出到.cshtml文件中显示*/ 1.先说说.ne ...

  6. AspNetPager 样式以及使用(漂亮)

    自定义样式: <style type="text/css"> /*拍拍网风格*/ .paginator { font: 11px Arial, Helvetica, s ...

  7. c#静态构造函数

    作用是初始化一些类的静态成员 1.在实例化类的对象,或者引用任何的静态成员之前,.Net自动调用此构造函数,而且只调用一次 2.没有任何修饰符,也没有参数 3.一个类只能有一个静态构造函数 4.无参的 ...

  8. MFC 定义和调用全局变量的一种方法

    在CTestApp.h中声明一个int x;然后调用的方式如下: CTestApp *app = (CTestApp *)AfxGetApp(); //生成指向应用程序类的指针,Test处改为对应的项 ...

  9. Service Provider模式

    参考文章:[http://blog.csdn.net/zl3450341/article/details/7227197] Service Interface:服务接口,将服务通过抽象统一声明,供客户 ...

  10. HTML5中createPattern()

    定义和用法 createPattern() 方法在指定的方向内重复指定的元素. 元素可以是图片.视频,或者其他 <canvas> 元素. 被重复的元素可用于绘制/填充矩形.圆形或线条等等. ...