*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 5145 NPY and girls 莫队+逆元
NPY and girls Problem Description NPY's girlfriend blew him out!His honey doesn't love him any more! ...
- 初探Docker
本文旨在让大家了解什么是Docker,并带领大家体验Docker使用的整个流程. 开启Docker学习之旅前,我们简单描述几个场景,应该很多人都有碰到过: 小凹同学开发了一个web应用,服务器环境是: ...
- -webkit-text-size-adjust
ios使用-webkit-text-size-adjust禁止调整字体大小 body{-webkit-text-size-adjust: 100%!important;} android使用以下代码, ...
- 第一个vs2013控制台程序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- js Array对象
http://www.w3cschool.cc/js/js-obj-array.html 创建新方法 原型是JavaScript全局构造函数.它可以构建新Javascript对象的属性和方法. 实例: ...
- shell中命令之间数据的传递
1.管道 "|" ls | cat -n > out.txt 2. 子shell 2.1 子shell 说明 在shell脚本中可以用()操作符可以定义一个子shell #/ ...
- linux 服务初识
1. daemon 和 service 系统为了实现某些功能,必须提供一些服务(service),但是service的提供总是需要进程的运行,实现service 的程序我们称为daemon(“守护神” ...
- Sphinx 全量索引加实时索引
source mysql { type = mysql sql_host = 10.10.3.181 sql_user = root sql_pass = dsideal sql_db = dside ...
- Leetcode Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- Codeforces Round #244 (Div. 2) A. Police Recruits
题目的意思就是找出未能及时处理的犯罪数, #include <iostream> using namespace std; int main(){ int n; cin >> ...