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. (栈的应用5.2.2)POJ 2106 Boolean Expressions(表达式求值)

    /* * POJ_2106.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...

  2. 为该目录以及子目录添加index.html

    add index.html to a directory recursively using Perl5 使用的目录,是从Perl下载的perl5.18.2的文档 Look Here #!/usr/ ...

  3. js实现通用的微信分享组件示例

    一.可定义的信息 1.分享时显示的LOGO:2.分享LOGO的宽度:3.分享LOGO的高度:4.分享出去显示的标题(默认调用网页标题):5.分享出去显示的描述(默认调用网页标题):6.分享链接(默认为 ...

  4. Dive into python学习笔记

    http://woodpecker.org.cn/diveintopython/index.html 1.第一个程序odbchelper.py def buildConnectionString(pa ...

  5. Java的Properties类和读取.properties文件

    一..properties文件的作用 Properties属性文件在JAVA应用程序中是经常可以看得见的,也是特别重要的一类文件.它用来配置应用程序的一些信息,不过这些信息一般都是比较少的数据,没有必 ...

  6. ubuntu下安装花生壳

    下载地址:http://hsk.oray.com/download/#type=linux 官方的文档: 花生壳(公网版) for linux的安装以及使用 Linux花生壳(公网版)将大大简化大家的 ...

  7. 华东交通大学2016年ACM“双基”程序设计竞赛 1010

    Problem Description LB是个十分喜欢钻研的人,对什么事都要搞明白.有一天他学习到了阶乘,他十分喜欢,所以他在想一个问题.如果给定一个数n,求n!能不能被2016整除.LB算了好久都 ...

  8. invoke和beginInvoke

    首先说下,invoke和begininvoke的使用有两种情况: 1. control中的invoke.begininvoke. 2. delegrate中的invoke.begininvoke. 这 ...

  9. 2016年12月4日 星期日 --出埃及记 Exodus 20:25

    2016年12月4日 星期日 --出埃及记 Exodus 20:25 If you make an altar of stones for me, do not build it with dress ...

  10. AB串(上帝都不会,我就没救了)

    [题目分析] 设答案的长度为m,