Watch The Movie

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 7585    Accepted Submission(s): 2427

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
 
 
题意:duoduo给N部片打了分,可以看L分钟片,店里只一次性卖M部片(最开始忽略了这个条件),每部片有长度,问duoduo在L分钟内看完这M部片可以的到的最高分。
 
读清了题还是不难。
 
 
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; int dp[][];
int cost,val;
int n,m,l; void zero_one(int cost,int val)
{ for(int j=l;j>=cost;j--)
for(int k=m;k>=;k--)
if(dp[j-cost][k-]>=)
dp[j][k]=max(dp[j][k],dp[j-cost][k-]+val);
}
int main()
{ int t;
scanf("%d",&t);
while(t--)
{
memset(dp,-,sizeof(dp));
dp[][]=;
scanf("%d%d%d",&n,&m,&l);
for(int i=;i<n;i++)
{
scanf("%d%d",&cost,&val);
zero_one(cost,val);
}
int res=;
for(int i=;i<=l;i++)
if(res<dp[i][m])
res=dp[i][m];
printf("%d\n",res);
}
return ;
}
 
 

HDU_3496_(二维费用背包)的更多相关文章

  1. hdu2159二维费用背包

    题目连接 背包九讲----二维费用背包 问题 二维费用的背包问题是指:对于每件物品,具有两种不同的费用:选择这件物品必须同时付出这两种代价:对于每种代价都有一个可付出的最大值(背包容量).问怎样选择物 ...

  2. 洛谷 P1507 NASA的食物计划 【二维费用背包】 || 【DFS】

    题目链接:https://www.luogu.org/problemnew/show/P1507 题目背景 NASA(美国航空航天局)因为航天飞机的隔热瓦等其他安全技术问题一直大伤脑筋,因此在各方压力 ...

  3. Regionals 2014 >> Asia - Taichung 7003 - A Balance Game on Trees 树形DP + 二维费用背包

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  4. 洛谷 P1509 找啊找啊找GF(复习二维费用背包)

    传送门 题目背景 "找啊找啊找GF,找到一个好GF,吃顿饭啊拉拉手,你是我的好GF.再见." "诶,别再见啊..." 七夕...七夕...七夕这个日子,对于sq ...

  5. codevs1959拔河比赛(二维费用背包)

    1959 拔河比赛  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold     题目描述 Description 一个学校举行拔河比赛,所有的人被分成了两组,每个人 ...

  6. 榨取kkksc03 luogu1855 dp 裸二维费用背包

    首先对于这个题目背景,,个人认为很(you)好(qu),,, 核心就是一个裸的二维费用背包,刚刚学习的同学参见dd大牛的背包九讲 #include <cstdio> #include &l ...

  7. hdu_2159(二维费用背包)

    HDU_2159 二维费用背包问题 http://acm.hdu.edu.cn/showproblem.php?pid=2159 #include<cstdio> #include< ...

  8. HDU 2159 FATE(二维费用背包)

    FATE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  9. HDU 2159 FATE (DP 二维费用背包)

    题目链接 题意 : 中文题不详述. 思路 : 二维背包,dp[i][h]表示当前忍耐值为i的情况下,杀了h个怪得到的最大经验值,状态转移方程: dp[i][h] = max(dp[i][h],dp[i ...

随机推荐

  1. 蓝桥杯 地宫寻宝 带缓存的DFS

      历届试题 地宫取宝   时间限制:1.0s   内存限制:256.0MB      问题描写叙述 X 国王有一个地宫宝库. 是 n x m 个格子的矩阵. 每一个格子放一件宝贝. 每一个宝贝贴着价 ...

  2. 动态生成页面(一)——ASP.NET中Literal使用

    在页面中加入内容时,假设是静态内容.无需使用容器,能够直接将标记作为HTML直接加入到页面中:可是,假设是动态内容,则必须借助容器将内容加入到页面中.典型的容器有:Label控件.Literal控件. ...

  3. linux 经常使用网络命令

    1. ifconfig ifconfig主要是能手动启动.观察和改动网络接口的相关參数.能改动的參数许多,包含IP參数及MTU等都能改动,他的语法例如以下:  [root@linux ~]# ifco ...

  4. HDU 5475An easy problem 离线set/线段树

    An easy problem Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. BZOJ 1055 区间DP

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1144  Solved: 668[Submit][Statu ...

  6. JS的内存空间

    变量对象与引用数据 概念解释 对于基本数据类型Undefined.Null.Boolean.Number.String往往保存在变量对象中 而对于引用数据类型,如Array.String.Object ...

  7. IJ:工程配置Tomcat

    ylbtech-IJ:工程配置Tomcat 1.返回顶部 1. 1.2. 1.3. 1.4. 2. 2.返回顶部 1. 2. 3.返回顶部 1. 2. 4.返回顶部 0.修改文件位置 D:\work- ...

  8. Java DAO模式

    DAO模式: DAO(DateAccessObject,数据存取对象) 位于业务逻辑和持久化数据之间,实现对持久化数据的访问. DAO组成: DAO接口: 数据库的所有操作定义成抽象方法,可以提供多种 ...

  9. bzoj 1660: [Usaco2006 Nov]Bad Hair Day 乱发节【单调栈】

    开一个单调递减的单调栈,然后用sum数组维护每个点的答案,新加点的时候一边退栈一边把退掉的点的sum加进来 #include<iostream> #include<cstdio> ...

  10. bzoj 1603: [Usaco2008 Oct]打谷机【瞎搞】

    一棵树,碰到改变转向的边就异或一下,从1dfs一遍 #include<iostream> #include<cstdio> using namespace std; const ...