题意:在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. 在CentOS中配置java jdk环境

    方法一. 1.查看yum库中都有哪些jdk版本(暂时只发现了openjdk) [root@localhost ~]# yum search java|grep jdkldapjdk-javadoc.x ...

  2. java创建线程方式

    1.继承Thread类 public class ThreadCreator extends Thread{ public static void main(String[] args) { //第一 ...

  3. Jquery实现下拉tab切换

    //需求:分别点击html,css,js元素时展示对应的列表内容,其他列表内容要自动收起来 //代码如下 <!DOCTYPE html> <html lang="en&qu ...

  4. 吴裕雄--天生自然JAVA数据库编程:使用JDBC连接ORACLE数据库

    DROP TABLE person ; DROP SEQUENCE myseq ; CREATE SEQUENCE myseq ; CREATE TABLE person ( id INT PRIMA ...

  5. CF 1198 A. MP3 模拟+滑动窗口

    A. MP3   题意:给你n个数,一个大小为8*I的容量,保存一个数需要多少容量取决于给定n个数的种类k,用公式 log2 k   计算,如果给定的容量不能保存所有数,选择减少数的种类来降低保存一个 ...

  6. BusyBox 添加 自定义命令\小程序 (applet)

    背景 在做嵌入式开的时候,busybox无疑是非常好用的命令集,所以很多时候都喜欢把busybox移植到我们的系统里面. 说明 添加一个很简单的命令--hello_busybox,输出"He ...

  7. 虚拟机上安装SVN服务

    服务器端安装SVN(centos)1.yum install subversion2.svn的相关配置1创建一个SVN仓库(所有项目存放与管理)mkdir -p /svndata/projects2. ...

  8. 解题报告:luogu P2678 跳石头

    题目链接:P2678 跳石头 很简单的二分查找,可悲的是我并不会. 不过题解贴心的写得很清楚(学会了套路) 二分一次判断一次,复杂度是\(O(nlogl)\),可以通过此题. \(Code:\) #i ...

  9. MySQL之表、列别名及各种JOIN连接详解

    MySQL在SQL中,合理的别名可以让SQL更容易以及可读性更高.别名使用as来表示,可以分为表别名和列别名,别名应该是先定义后使用才对,所以首先要了解sql的执行顺序(1) from(2) on(3 ...

  10. java不要登录发送邮件noReply

    最近在工作中遇到一个问题: 客户需要让我们的系统给他们发邮件,但是不给我们提供用户密码. 这样就导致一个问题,即,一般我们使用的都是smtp方式发邮件,发邮件的时候必须登录,虽然可以修改发件人的邮箱名 ...