UVA - 12563 Jin Ge Jin Qu hao(劲歌金曲)(0-1背包+滚动数组)
题意:在KTV唱歌剩下的t秒时间内,决定选最爱的n首歌中的一部分歌,在时间结束之前唱一首时长678秒的《劲歌金曲》,使得唱的总曲目尽量多(包括《劲歌金曲》),在此前提下尽量晚的离开KTV。(n<=50,t<=109)
分析:
1、输入保证所有n+1首曲子总长度严格大于t,虽然,t<=109,实际上t不会超过180n+678。
2、dp[i]剩余时间为i时唱的总曲目,time[i]剩余时间为i时唱歌时间总长度。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int dp[MAXT];
int time[MAXT];
int main(){
int T;
scanf("%d", &T);
int kase = 0;
while(T--){
int n, t;
scanf("%d%d", &n, &t);
memset(dp, 0, sizeof dp);
memset(time, 0, sizeof time);
int len = Min(t - 1, 180 * n);
for(int i = 0; i < n; ++i){
int x;
scanf("%d", &x);
for(int j = len; j >= 0; --j){
if(j >= x){
if(dp[j - x] + 1 > dp[j]){
dp[j] = dp[j - x] + 1;
time[j] = time[j - x] + x;
}
else if(dp[j - x] + 1 == dp[j]){
time[j] = Max(time[j], time[j - x] + x);
}
}
}
}
int ansnum = -1;
int anstime = 0;
for(int i = len; i >= 0; --i){
if(dp[i] > ansnum){
ansnum = dp[i];
anstime = time[i];
}
else if(dp[i] == ansnum){
anstime = Max(anstime, time[i]);
}
}
printf("Case %d: %d %d\n", ++kase, ansnum + 1, anstime + 678);
}
return 0;
}
UVA - 12563 Jin Ge Jin Qu hao(劲歌金曲)(0-1背包+滚动数组)的更多相关文章
- UVA Jin Ge Jin Qu hao 12563
Jin Ge Jin Qu hao (If you smiled when you see the title, this problem is for you ^_^) For those who ...
- UVA - 12563 Jin Ge Jin Qu hao (01背包)
InputThe first line contains the number of test cases T (T ≤ 100). Each test case begins with two po ...
- 12563 Jin Ge Jin Qu hao
• Don’t sing a song more than once (including Jin Ge Jin Qu). • For each song of length t, either si ...
- uVa 12563 Jin Ge Jin Qu
分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...
- 12563 - Jin Ge Jin Qu hao——[DP递推]
(If you smiled when you see the title, this problem is for you ^_^) For those who don’t know KTV, se ...
- 一道令人抓狂的零一背包变式 -- UVA 12563 Jin Ge Jin Qu hao
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- UVa 12563 Jin Ge Jin Qu hao【01背包】
题意:给出t秒时间,n首歌分别的时间a[i],还给出一首长度为678的必须唱的劲歌金曲,问最多能够唱多少首歌(只要最后时间还剩余一秒,都可以将劲歌金曲唱完) 用dp[i]代表花费i时间时唱的歌的最大数 ...
- UVA - 12563 Jin Ge Jin Qu hao (01背包变形)
此题应该注意两个点,首先背包容量应该缩减为t-1,因为最长的歌不超过三分钟,而劲歌金曲有678s,所以肯定要留出这个时间来.其次注意优先级,保证唱的歌曲数目最多,在此前提下尽可能的延长时间. 处理方法 ...
- Uva 12563 Jin Ge Jin Qu hao(01背包)
题意: 假定你在唱KTV,还剩下t秒时间.你决定接下来唱你最喜爱的n首歌(不包含劲歌金曲)中的一些歌曲.在时间结束之前再唱一个劲歌金曲.使得唱的歌的总曲目尽量多以及时间总长度. 输入保证所有n+1曲子 ...
随机推荐
- IDEA代码检验出错
该软件功能过于强大,会自动检验执行所需要的代码,所以会报错,但实际上我们有写 例如 解决方法 File-->setting 将error改为warning
- PHP几个快速读取大文件例子
PHP几个快速读取大文件例子 感谢 把我给崩了 的投递 时间:2014-10-16 来源:三联 在PHP中,对于文件的读取时,最快捷的方式莫过于使用一些诸如file.file_get_contents ...
- 复习hibernate
Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库. Hibernate可以应用在任何使用JDB ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:快速浮动
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 将OB86的故障信息保存在DB86中去
出现DP站故障的时候,CPU会自动调用OB86 ,OB86 的20B 局部变量里面有丰富的故障信息,生成数据块DB86 在DB86 中生成5个双字元素的数组ARAY 在OB86中调用 "BL ...
- Oracle删除重复数据并且只留其中一条数据
数据库操作中,经常会因为导数据造成数据重复,需要进行数据清理,去掉冗余的数据,只保留正确的数据 一:重复数据根据单个字段进行判断 1.首先,查询表中多余的数据,由关键字段(name)来查询. sele ...
- Compile-kernel-module
Compile-kernel-module 1. 内核模块编程1.1 简介1.2 加载内核模块1.3 最简单的模块1.4 模块必要信息1.4.1 内核模块必须至少包含的头文件:1.4.2 内核模块必须 ...
- python里的def 方法中->代表什么意思?
功能注释 函数注释是关于用户定义函数使用的类型的完全可选元数据信息(请参阅PEP 3107和 PEP 484了解更多信息). 注释__annotations__ 作为字典存储在函数的属性中,对函数的任 ...
- GoJS API学习
var node = {}; node["key"] = "节点Key"; node["loc"] = "0 0";// ...
- 洛谷P2089 烤鸡
标签:暴力,枚举 题目背景 猪猪 Hanke 得到了一只鸡. 题目描述 猪猪 Hanke 特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke 吃鸡很特别,为什么特别呢?因为他有 10 种配料(芥末. ...