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. RAII惯用法详解

    [1]什么是RAII惯用法? RAII是Resource Acquisition Is Initialization的缩写,意为“资源获取即初始化”. 它是C++之父Bjarne Stroustrup ...

  2. Notepad++编辑Pyhton文件的自动缩进的问题(图文)

    转自:http://www.xuebuyuan.com/1102224.html 这个问题一直困扰我很久,Python对缩进很敏感,一般建议缩进用空格,而 Notepad++的自动缩进是用的TAB,g ...

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

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

  4. 修改Linux时间一般涉及到3个命令: date, clock, hwclock

    原贴:http://203.208.37.104/search?q=cache:p1vAAHvs9ikJ:www.goldthe.com /blog/%3Faction%3Dshowlog%26gid ...

  5. [ERROR][org.springframework.web.context.ContextLoader][main] Context initialization failed org.sprin

    做一个SSH为基础框架的webapp小DEMO,复制了一把以前可以跑的代码,竟发现无法初始化数据源,报错如下: [ERROR][org.springframework.web.context.Cont ...

  6. 怎么使用Docker搭建PHP开发环境呢?

    在Docker流行之前,要搭建开发环境通常有两种选择:一种是使用wamp.xampp.mamp等集成开发环境安装包,另外一种就是使用普通虚拟机来安装linux服务器,然后通过下载一键安装包(如:lnm ...

  7. 25、oracle(一)

    1)了解oracle背景,概念和特点 2)掌握oracleSQL对单表各种查询操作 3)掌握oracleSQL中函数的使用 4)掌握数值型number,字符串型varchar2,日期型date,条件判 ...

  8. 21、JavaScript加强

      1)回顾JS中核心内容 2)了解WEB1.0和WEB2.0时代的技术与特点 3)理解AJAX的产生背景.工作原理与特点 4)掌握AJAX常用API及应用   声明:服务端我们使用Servlet技术 ...

  9. php的内存分配还是很智能的

    <?php echo memory_get_usage().PHP_EOL;$a = 1;$b = $a;echo memory_get_usage().PHP_EOL; <?php ec ...

  10. 【转】MYSQL入门学习之五:MYSQL的字符集

    转载地址:http://www.2cto.com/database/201212/175541.html MySQL的字符集支持(Character Set Support)有两个方面:字符集(Cha ...