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 ...
随机推荐
- 智能社区--HI3516C可视门禁研发出来咯
铝壳.非常大气的外壳. 200W像素,HI3516C,携带server.创新的产品.欢迎交流:QQ237753582 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5u ...
- easyui中点击datagrid的分页刷新按钮,数据无法更新到最新状态
原因分析:点击刷新按钮是对当前页数据进行reload,因此所传的请求参数皆为上一次加载当前页的参数即datagrid的load方法中的参数,主要是因为请求的最终时间无法更新到最新状态 解决方案:对点击 ...
- Session与Cookie解析
Session和Cookie这两个对象也接触了比較长的时间了,今天就来总结一下. 首先,他们都是会话跟踪中经常使用的技术.Cookie在client记录信息来确定用户身份,Session在服务端记录信 ...
- Android 代码设置Activity 背景透明
当指定Activity 样式 Them.Dialog 时候 又不同意用XML 设置 Activity 的背景颜色的时候 用代码 this.getWindow().getDecorView().setB ...
- 嵌入式开发之8127---DM8127如何利用EDMA搬移数据
--------------qq:1327706646 ---------------------author:midu -------------------------------datetime ...
- Visual Studio静态编译
1.Visual Studio静态编译设置: [Project]-[prj_name Properties],按例如以下框设置 2.why配置成静态编译? 假设动态编译,在没有安装Visual Stu ...
- go16---select
package main /* Channel Channel 是 goroutine 沟通的桥梁, goroutine是通过通信来进行内存的共享, 而不是通过内存的共享来进行通信,通过Channel ...
- Error处理: android.media.MediaRecorder.start(Native Method) 报错:start failed: -19【转】
本文转载自:http://blog.csdn.net/netwalk/article/details/17686993 Error处理: android.media.MediaRecorder.sta ...
- ModuleNotFoundError: No module named 'PIL'
错误:ModuleNotFoundError: No module named 'PIL' 解决办法: pip install Pillow
- 第七周 Leetcode 466. Count The Repetitions 倍增DP (HARD)
Leetcode 466 直接给出DP方程 dp[i][k]=dp[i][k-1]+dp[(i+dp[i][k-1])%len1][k-1]; dp[i][k]表示从字符串s1的第i位开始匹配2^k个 ...