题意:在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背包+滚动数组)的更多相关文章

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

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

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

  4. uVa 12563 Jin Ge Jin Qu

    分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...

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

  6. 一道令人抓狂的零一背包变式 -- UVA 12563 Jin Ge Jin Qu hao

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  7. UVa 12563 Jin Ge Jin Qu hao【01背包】

    题意:给出t秒时间,n首歌分别的时间a[i],还给出一首长度为678的必须唱的劲歌金曲,问最多能够唱多少首歌(只要最后时间还剩余一秒,都可以将劲歌金曲唱完) 用dp[i]代表花费i时间时唱的歌的最大数 ...

  8. UVA - 12563 Jin Ge Jin Qu hao (01背包变形)

    此题应该注意两个点,首先背包容量应该缩减为t-1,因为最长的歌不超过三分钟,而劲歌金曲有678s,所以肯定要留出这个时间来.其次注意优先级,保证唱的歌曲数目最多,在此前提下尽可能的延长时间. 处理方法 ...

  9. Uva 12563 Jin Ge Jin Qu hao(01背包)

    题意: 假定你在唱KTV,还剩下t秒时间.你决定接下来唱你最喜爱的n首歌(不包含劲歌金曲)中的一些歌曲.在时间结束之前再唱一个劲歌金曲.使得唱的歌的总曲目尽量多以及时间总长度. 输入保证所有n+1曲子 ...

随机推荐

  1. 二十、oracle通过复合索引优化查询及不走索引的8种情况

    1. 理解ROWID ROWID是由Oracle自动加在表中每行最后的一列伪列,既然是伪列,就说明表中并不会物理存储ROWID的值:你可以像使用其它列一样使用它,只是不能对该列的值进行增.删.改操作: ...

  2. SSH、SSL与HTTPS的联系

    SSH 维基百科中对SSH协议的定义如下 Secure Shell(缩写为SSH),由IETF的网络工作小组(Network Working Group)所制定:SSH为一项创建在应用层和传输层基础上 ...

  3. Bootstrap入门(一)准备

    Bootstrap入门(一)准备         网页的样式化与布局展示是很多开发者要面对的问题,目前有多的框架和工具包,可以使网页设计的任务变得更加简单.轻松.方便.快捷一些,其中,bootstra ...

  4. C语言学习从入门到精通书籍,10万读者都认可

    C语言程序设计从入门到精通 10万读者认可的编程图书精粹 零基础自学编程的入门图书 详解C语言编程思想和核心技术 很多初学者,对C语言.c++的概念都是模糊不清的,C语言.c++是什么,能做什么,学的 ...

  5. zabbix WebUI自定义Nginx监控项模板

    zabbix webUI自定义Nginx监控项模板 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.创建模板 1>.如下图所示,依次点击"配置" --- ...

  6. 浅谈Spring 5的响应式编程

    这篇使用Spring 5进行响应式编程的入门文章展示了你现在可以使用的一些新的non-blocking, asynchronous.感谢优锐课老师给予的指导! 近年来,由于响应式编程能够以声明性的方式 ...

  7. Java 的 String.split 函数,消除空字符串

    代码: String str = "the music made it hard to concentrate"; String delims = "[ ]+" ...

  8. 7.1 Varnish VCL

    根据以上的配置增加集群,修改default.vcl # This ) # man page for details on VCL syntax and semantics. # # Default b ...

  9. IIS7/8 HTTP Error 500.19 错误 0x80070021 错误代码:0x8007000d

    nopCommerce versions 4.20 的安装环境是 dotnet-hosting-2.2.0-win.exe .net core项目iis10上出现 HTTP 错误 500.19,错误代 ...

  10. Angular2的双向数据绑定

    什么是双向绑定 如图:   双向绑定.jpg 双向绑定机制维护了页面(View)与数据(Data)的一致性.如今,MVVM已经是前段流行框架必不可少的一部分. Angular2中的双向绑定 双向绑定, ...