【Link】:

【Description】



KTV给你T秒的唱歌时间;

你有n首一定要唱的歌;

然后有一首很变态的歌有678s,你想在T秒结束之前唱一下这首歌;

因为这样的话,你能尽量晚地走出KTV(不会在你唱到一半的时候让你不唱了),即你最后的唱歌时间是可以超过T秒的;

告诉你n首歌的时间;

这n首歌里面任选几道唱,但必须要留一点时间唱那首变态的歌;

问你最多能唱多少首歌,然后在唱歌最多的基础上,问你最晚能什么时候走出KTV

【Solution】



如果∑a[i]<T的话,则直接输出答案n+1和∑a[i] + 678;

否则;

计算在T-1秒内,你最多能唱多少首歌(不包括那首变态的歌);

(即最少留一秒钟开始唱那首变态的歌);

即设f[i]表示花费恰好i秒,最多能唱多少首除了那首变态的歌之外的歌;

最后逆序从T-1到0里面找下标最大(即时间)的,且f值最大的f[idx]

,输出f[idx]+1,和idx+678即可;



【NumberOf WA】



1



【Reviw】



忘记处理∑a[i] < T的情况了;



【Code】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 50; int n,t;
int a[N+20],f[N*180+10]; int main(){
//Open();
//Close();
int T,kk = 0;
scanf("%d",&T);
while (T--){
kk++;
scanf("%d%d",&n,&t);
int sum = 0;
rep1(i,1,n){
scanf("%d",&a[i]);
sum+=a[i];
}
//f[i]代表花费时间为i,最多能唱多少首歌
f[0] = 0;
if (t > sum){
printf("Case %d: %d %d\n",kk,n+1,sum + 678);
continue;
}
rep1(i,1,t-1)
f[i] = -1;
rep1(i,1,n){
rep2(j,t-1,a[i])
if (f[j-a[i]]>=0)
f[j] = max(f[j],f[j-a[i]] + 1);
}
int ma = -1,idx;
rep2(i,t-1,0)
if (f[i]>ma){
ma = f[i],idx = i;
}
//678s
printf("Case %d: %d %d\n",kk,ma+1,idx + 678);
}
return 0;
}

【UVa 12563】Jin Ge Jin Qu hao的更多相关文章

  1. uVa 12563 Jin Ge Jin Qu

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

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

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

  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 11464】 - Even Parity 偶数矩阵

    偶数矩阵(Even Parity, UVa 11464) 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1,使得每个元素的上.下.左.右的元素(如果存在的话)之和均为偶数.比 ...

  7. 【贪心+中位数】【UVa 11300】 分金币

    (解方程建模+中位数求最短累积位移) 分金币(Spreading the Wealth, UVa 11300) 圆桌旁坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一 ...

  8. 【UVa 10881】Piotr's Ants

    Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...

  9. 【UVa 116】Unidirectional TSP

    [Link]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

随机推荐

  1. Android 实现下拉刷新和上拉加载更多的RECYCLERVIEW和SCROLLVIEW

    PullRefreshRecyclerView.java /** * 类说明:下拉刷新上拉加载更多的RecyclerView * Author: gaobaiq * Date: 2016/5/9 18 ...

  2. sqluldr2linux64.bin的使用

    使用sqluldr2linux64.bin的前提是已经安装了Oracle数据库,sqluldr2linux64.bin和Oracle在同一台主机上使用,使用之前需要赋予可执行权限: [root@nod ...

  3. 【参考】查找Oracle最高的几个等待事件以及锁的信息

    1.通过操作系统的命令找到系统资源的bottleneck,如:CPU, Memory, I/O, Network  同时主要关注IOWait, PI/PO, Memory的使用情况 2.通过查询v$s ...

  4. grant 命令

    创建拥有所有权限账户.可以远程连接.并且允许用户再将该权限授予其它用户: grant all privileges on *.* to root @"%" identified b ...

  5. HDU-2896 病毒侵袭 字符串问题 AC自动机

    题目链接:https://cn.vjudge.net/problem/HDU-2896 题意 中文题 给一些关键词和一个字符串,问字符串里包括了那几种关键词 思路 直接套模版 改insert方法,维护 ...

  6. LightOJ-1138 Trailing Zeroes (III) 唯一分解定理 算n!的某个因数个数

    题目链接:https://cn.vjudge.net/problem/ 题意 找一个最小的正整数n 使得n!有a个零 思路 就是有几个因数10呗 考虑到10==2*5,也就是说找n!因数5有几个 数据 ...

  7. 学习CV:《OpenCV 3计算机视觉Python语言实现第2版》中文PDF+英文PDF+代码

    理解与计算机视觉相关的算法.模型以及OpenCV 3 API背后的基本概念,有助于开发现实世界中的各种应用程序(比如:安全和监视领域的工具). OpenCV 3是一种先进的计算机视觉库,可以用于各种图 ...

  8. caioj 1153 扩展欧几里德算法(解不定方程)

    模板题 注意exgcd函数要稍微记一下 #include<cstdio> #include<cctype> #include<algorithm> #define ...

  9. Qt之QStackedLayout

    简述 QStackedLayout继承自QLayout. QStackedLayout类提供了多页面切换的布局,一次只能看到一个界面. QStackedLayout可用于创建类似于QTabWidget ...

  10. ubuntu鼠标和触摸板的禁用

    ubuntu鼠标和触摸板的禁用 学习了:http://www.2cto.com/os/201308/239403.html 在终端下直接执行以下命令来打开或关闭触摸板. sudo modprobe - ...