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. Servlet概念框架

    以 Servlet 3.0 源代码为基础.Servlet 是 Javaweb 应用的基础框架,犹如孙子兵法之于作战指挥官,不可不知. 概念框架 机制: 事件 Event, 监听器 Listener 数 ...

  2. iOS 学习笔记 十 (2015.04.03)xcode第三方插件

    1.xcode第三方插件,存放路径:~/Library/Application Support/Developer/Shared/Xcode/Plug-ins

  3. ubuntu 修改终端命令显示的颜色

    转于  http://www.blogbus.com/riusksk-logs/62891140.html 修改当前用户 gedit ~/.bashrc 在最后一行下面添加这行 PS1='${debi ...

  4. SpringMVC整合TaskExecutor线程池的配置/使用

    一.配置jdbc.properties添加: #------------ Task ------------ task.core_pool_size=5 task.max_pool_size=50 t ...

  5. 几个常见的Laravel报错及解决方法

    报错:「Can't swap PDO instance while within transaction」 transactions >= 1) {throw new RuntimeExcept ...

  6. 29、Oralce(五)

    1)掌握PLSQL程序设计 2)掌握存储过程,函数和触发器 3)了解一些oralceSQL语句优化方案 ------------------------------------------------ ...

  7. C#:通过Window API接口实现WiFi

    1.获取Mac地址 //WiFi通知回调 private WlanApi.WLAN_NOTIFICATION_CALLBACK _notificationCallback; this._notific ...

  8. C#:只运行一个程序

    一.通过系统事件 1.实现如下: using System; using System.Collections.Generic; using System.Linq; using System.Tex ...

  9. PullToRefresh 下拉刷新的样式修改

    资源文件结构图, 先看看下拉刷新头的布局, <?xml version="1.0" encoding="utf-8"?> <merge xml ...

  10. ACM题目————还是畅通工程

    Submit Status Description 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离.省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路 ...