HDU_3496_(二维费用背包)
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
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.
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.
3 2 10
11 100
1 2
9 1
#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_(二维费用背包)的更多相关文章
- hdu2159二维费用背包
题目连接 背包九讲----二维费用背包 问题 二维费用的背包问题是指:对于每件物品,具有两种不同的费用:选择这件物品必须同时付出这两种代价:对于每种代价都有一个可付出的最大值(背包容量).问怎样选择物 ...
- 洛谷 P1507 NASA的食物计划 【二维费用背包】 || 【DFS】
题目链接:https://www.luogu.org/problemnew/show/P1507 题目背景 NASA(美国航空航天局)因为航天飞机的隔热瓦等其他安全技术问题一直大伤脑筋,因此在各方压力 ...
- 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 ...
- 洛谷 P1509 找啊找啊找GF(复习二维费用背包)
传送门 题目背景 "找啊找啊找GF,找到一个好GF,吃顿饭啊拉拉手,你是我的好GF.再见." "诶,别再见啊..." 七夕...七夕...七夕这个日子,对于sq ...
- codevs1959拔河比赛(二维费用背包)
1959 拔河比赛 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 一个学校举行拔河比赛,所有的人被分成了两组,每个人 ...
- 榨取kkksc03 luogu1855 dp 裸二维费用背包
首先对于这个题目背景,,个人认为很(you)好(qu),,, 核心就是一个裸的二维费用背包,刚刚学习的同学参见dd大牛的背包九讲 #include <cstdio> #include &l ...
- hdu_2159(二维费用背包)
HDU_2159 二维费用背包问题 http://acm.hdu.edu.cn/showproblem.php?pid=2159 #include<cstdio> #include< ...
- HDU 2159 FATE(二维费用背包)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU 2159 FATE (DP 二维费用背包)
题目链接 题意 : 中文题不详述. 思路 : 二维背包,dp[i][h]表示当前忍耐值为i的情况下,杀了h个怪得到的最大经验值,状态转移方程: dp[i][h] = max(dp[i][h],dp[i ...
随机推荐
- ViewPager学习之仿微信主界面
由于素材的原因,这里都是从网上找的图片,所以所谓的仿微信实际上最后成了下图这货.. .,点击变色也是自己用的windows自带绘图的颜料桶填充的空白. .. watermark/2/text/aHR0 ...
- Linux改动/etc/profile配置错误command is not found自救方法
我的CSDN博客地址: http://blog.csdn.net/caicongyang 博主之前在改动了/etc/profile配置文件方法后,导致bash命令无法用 运行ls命令结果例如以下: - ...
- vs2013生成lib
引擎cocos2d-x-3.1.1 一. cocos创建一个项目.随便是lua还是cpp.这里用cpp演示 二.创建完毕之后执行下项目 之后创建两个类.例如以下 TestLib.cpp文件 #incl ...
- Delphi中处理URL编码解码
Delphi中处理URL编码解码 一.URL简单介绍 URL是网页的地址,比方 http://www.shanhaiMy.com. Web 浏览器通过 URL 从 web server请求页面 ...
- react 中的 setState
语法:setState(newState [,callback]) 1.只要有入门基础的同学都知道 setState({...}) 是更新组件中的 state 内容 2.但是,setState 是异步 ...
- Message: SyntaxError: unterminated string literal
#Message: SyntaxError: unterminated string literalmytxt = words.replace('\n','').replace('\r','') js ...
- charset='utf8mb4'
charset='utf8mb4' conn = pymysql.connect(host=h, port=pt, user=u, passwd=p, db=db, charset='utf8mb4' ...
- SoapUI中的RegEx
在for Content matching RegEx中
- oracle 统计/分析函数
Oracle从8.1.6开始提供分析函数,分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是对于每个组返回多行,而聚合函数对于每个组只返回一行. 语法: Sql代码 <analytic ...
- TI BLE: Advertisement
#define GAPROLE_ADVERT_ENABLED 0x305 //!< Enable/Disable Advertising. Read/Write. Size is uint8. ...