【UVa 12563】Jin Ge Jin Qu hao
【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的更多相关文章
- uVa 12563 Jin Ge Jin Qu
分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...
- 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 ...
- 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 ...
- 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 ...
- 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 11464】 - Even Parity 偶数矩阵
偶数矩阵(Even Parity, UVa 11464) 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1,使得每个元素的上.下.左.右的元素(如果存在的话)之和均为偶数.比 ...
- 【贪心+中位数】【UVa 11300】 分金币
(解方程建模+中位数求最短累积位移) 分金币(Spreading the Wealth, UVa 11300) 圆桌旁坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一 ...
- 【UVa 10881】Piotr's Ants
Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...
- 【UVa 116】Unidirectional TSP
[Link]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
随机推荐
- android之handler机制深入解析
一.android中需要另开线程处理耗时.网络的任务,但是有必须要在UI线程中修改组件.这样做是为了: ①只能在UI线程中修改组件,避免了多线程造成组件显示混乱 ②不使用加锁策略是为了提高性能,因为a ...
- win10关闭更新
计算机--管理: 找到windows update 服务关闭:
- jdk1.8源码分析-hashMap
在Java语言中使用的最多的数据结构大概右两种,第一种是数组,比如Array,ArrayList,第二种链表,比如ArrayLinkedList,基于数组的数据结构特点是查找速度很快,时间复杂度为 O ...
- BZOJ2225: [Spoj 2371]Another Longest Increasing CDQ分治,3维LIS
Code: #include <cstdio> #include <algorithm> #include <cstring> #define maxn 20000 ...
- 洛谷P4016 负载平衡问题 费用流
这道题还是很好的. 考察了选手对网络流的理解. 首先,任意两个相邻点之间的运货量时没有限制的. 我们可以将相邻点之间的流量建为无限大,单位费用设为 1,代表运输一个货物需耗费一个代价. 由于题目要求最 ...
- 移动端的vue项目,启动错误:Module build failed: Error: No PostCSS Config found in:
新建一个postcss.config.js 写上下面代码 `module.exports = { plugins: { 'autoprefixer': {browsers: 'last 5 versi ...
- PHP SOAP 教程
一.SoapServer 服务器 1.__construct 作用:创建 SoapServer 对象 用法:__construct ( mixed wsdl [, array options] ) 参 ...
- Vim配置及使用
Vim配置 1.打开~/.vimrc,将以下内容考入文件.vimrc中 "行号" set nu "高亮" syntax enable syntax on &qu ...
- Uart,IIC和SPI的区别
1.UART, SPI, IIC的详解 UART.SPI.IIC是经常用到的几个数据传输标准,下面分别总结一下: UART(Universal Asynchronous Receive Transmi ...
- 【BZOJ 1260】[CQOI2007]涂色paint
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 区间DP 设f[i][j]表示i..j这个区间变成目标需要的最少染色次数. f[i][i] = 1 然后考虑f[i][j]的产生方法 ...