HDU 3496 Watch The Movie(看电影)

Time Limit: 1000MS   Memory Limit: 65536K

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

新学期即将开始,DuoDuo明天就要去学校了。想了想之后忙碌的生活,她还是决定在今晚找找乐子。DuoDuo十分喜欢欧美动画。因此她希望她叔叔买些回来晚上一起看。她爷爷却给她限定L分钟的时间看动画,之后必须去睡觉。

DuoDuo从1到N列了N部电影。对于她的最爱,统统都想要。她给出了对这N部电影的好感度Vi(Vi > 0)。数值越高,DuoDuo越喜欢。每部电影时长为Ti。DuoDuo一旦开始观看,就势必要看完。

但是奇葩的是,这家商店只出售M部影片(不多不少),这可难坏了她叔叔。如何才能在N部DuoDuo想要的DVDs中挑M部并且在不超过L的时间内收获最多的好感度?

聪明如你!定可助DuoDuo的叔叔一臂之力。

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

输入数据的第一行是一个整数t(1 ≤ t ≤ 10),表示测试用例的数量,随后的每个测试用例:

第一行:N(N <= 100),M(M<=N),L(L <= 1000)

N:DuoDuo想买的DVD数量。

M:商店可出售的DVD数量。

L:她爷爷运行的最长观看时间。

第二到N+1行,每行两个数。第一个数字表示第i个DVD的时长,第二个数字表示DuoDuo对其的好感度。

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

包含一个数字。(小于2^31。)

DuoDuo今晚收获的好感度。

如果DuoDuo不能看完她叔叔所买的电影则输出0。

【Sample Input - 输入样例】

【Sample Output - 输出样例】

1

3 2 10

11 100

1 2

9 1

3

【题解】

  二维01背包

  (之前为了看(qiang)着(po)爽(zheng)用vector来写,写着写着代码量比预期越来越高,于是默默地放弃了……)

  最后的好感度V太大,不过时间T和DVD的数量N都不大,可以用来当坐标轴。

  考虑到T或N在某一状态都可能相同,因此T与N都应该成为坐标轴,其值为V。

  这么看来就是一个二维的01背包了。 V[T][N]或V[N][T]怎么开都行。

【代码 C++】

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define time 1005
#define cdSUM 105
int main(){
int ts, i, j, t, v, n, m, tLimt, cd[cdSUM][], value[time][cdSUM];
scanf("%d", &ts);
while (ts--){
memset(value, , sizeof(value));
scanf("%d%d%d", &n, &m, &tLimt);
while (n--){
scanf("%d%d", &t, &v);
for (i = tLimt - ; i > ; --i){
for (j = ; j < m; ++j){
if (value[i][j] && i + t <= tLimt){
value[i + t][j + ] = std::max(value[i][j] + v, value[i + t][j + ]);
}
}
}
value[t][] = std::max(v, value[t][]);
}
for (i = v = ; i <= tLimt; ++i) v = std::max(v, value[i][m]);
printf("%d\n", v);
}
return ;
}

HDU 3496 Watch The Movie(看电影)的更多相关文章

  1. 开始ubuntu 14.04 的装X模式---终端模式下中文输入,听歌,上irc 开启framebuffer看电影 截图

    先上图吧 卡卡的全是在tty1 下的操作,看电影,听歌,截图 ,看图  ,上irc 等等,相当适合在小白面前装屁! 需要安装的软件: 为了能正常显示中文:安装fbterm sudo apt-get i ...

  2. UESTC_邱老师看电影 2015 UESTC Training for Dynamic Programming<Problem F>

    F - 邱老师看电影 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  3. [ZJOI2011]看电影(MOVIE)

    题目描述 到了难得的假期,小白班上组织大家去看电影.但由于假期里看电影的人太多,很难做到让全班看上同一场电影,最后大家在一个偏僻的小胡同里找到了一家电影院.但这家电影院分配座位的方式很特殊,具体方式如 ...

  4. 【BZOJ2227】[ZJOI2011]看电影(组合数学,高精度)

    [BZOJ2227][ZJOI2011]看电影(组合数学,高精度) 题面 BZOJ 洛谷 题解 这题太神仙了. 首先\(K<N\)则必定无解,直接特判解决. 现在只考虑\(K\ge N\)的情况 ...

  5. 用Emacs看电影

    大多数人用emacs听歌,我却喜欢用emacs看电影.用 EMMS 和 mplayer 结合,看电影真是太方便了. 不要从源里安装EMMS,它可能给你安装别的播放器,没必要,我们有 mplayer 足 ...

  6. UESTC 2015dp专题 F 邱老师看电影 概率dp

    邱老师看电影 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...

  7. 我追一个处女座的女孩快两个月了,我之前聊得很好,她说过有空call我去看电影,过了一个月她就不理我了,我喜欢她, 我是程序员,百度发不了那么多字。

    她刚刚进公司的时候,公司组织去打球,我叫她一起去她也去了,我和她聊了很多,聊得很自然,很开心,如我是哪个学习毕业的 我出来工作多久了等,她也聊了 她自己好多,她现在在读大学,只有周日上一天课那种. 我 ...

  8. 【BZOJ2227】【ZJOI2011】看电影 [组合数][质因数分解]

    看电影 Time Limit: 10 Sec  Memory Limit: 259 MB[Submit][Status][Discuss] Description 到了难得的假期,小白班上组织大家去看 ...

  9. Zjoi2011 看电影

    最近在学习一些概率的东西.. 一个随机试验称为 Laplace 试验,当且仅当它满足如下两个条件: (ⅰ) 试验结果 (样本点) 的个数是有限的.(Ω 是有限集) (ⅱ) 任意两个基本事件的概率均相等 ...

随机推荐

  1. HDU4288:Coder(线段树单点更新版 && 暴力版)

    Problem Description In mathematics and computer science, an algorithm describes a set of procedures ...

  2. JVM学习笔记(三)------内存管理和垃圾回收【转】

    转自:http://blog.csdn.net/cutesource/article/details/5906705 版权声明:本文为博主原创文章,未经博主允许不得转载. JVM内存组成结构 JVM栈 ...

  3. grep DEMO

    测试数据: [xiluhua@vm-xiluhua][~]$ cat msn.txt aaa bbb bbb ccc ccc ddd bbb eee aaa ccc bbb sss [xiluhua@ ...

  4. oracle监听服务无法打开

    原因: 修改了主机名,但没有修改监听文件listener.ora里面的配置. 解决办法:修改HOST与主机名相同 LISTENER = (DESCRIPTION_LIST = (DESCRIPTION ...

  5. MyISAM表杂记实验

    一.本文说明 由于刚学mysql所以动手做了一些实验. 二.实验内容 1.验证MyISAM有AUOT_INCREMENT coloumn功能 ----在这里是对现有表t,增加一个主键----mysql ...

  6. Android应用插件式开发解决方法

    转自:http://blog.csdn.net/arui319/article/details/8109650 一.现实需求描述 一般的,一个Android应用在开发到了一定阶段以后,功能模块将会越来 ...

  7. jqeury.base

    min.js //前台调用 var $ = function (args) { return new Base(args); } //基础库 function Base(args) { //创建一个数 ...

  8. PostgreSQL中使用外部表

    1. 安装file_fdw 需要先安装file_fdw,一般是进到PostgreSQL的源码包中的contrib/file_fdw目录下,执行: make make install 然后进入数据库中, ...

  9. JavaScript DOM 编程艺术(第2版)读书笔记(4)

    案例研究:JavaScript 图片库 改变图片的src属性的两种方式: 1,setAttribute方法是“第1级DOM”的组成部分,它可以设置元素节点的任意属性. 2,element.src = ...

  10. YTU 2019: 鞍点计算

    2019: 鞍点计算 时间限制: 1 Sec  内存限制: 64 MB 提交: 66  解决: 30 题目描述 找出具有m行n列二维数组Array的"鞍点",即该位置上的元素在该行 ...