Jin Ge Jin Qu hao
题意:
n首歌和一首经典歌已知其长度,一首歌开始唱必须唱完,现在已知剩余时间,求最多能唱歌的个数并保证唱歌时间总长最大
分析:
留最后一个时间唱经典,然后对剩下的时间用背包求出最大个数,并求出总长最大的一个。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int n,t,dp[],a[];
int main()
{
int te,ca=;
scanf("%d",&te);
while(te--){
scanf("%d%d",&n,&t);
for(int i=;i<n;++i)
scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
int maxv=;
for(int i=;i<n;++i)
for(int j=t-;j>=a[i];--j){
if(dp[j-a[i]]>||j==a[i])
dp[j]=max(dp[j],dp[j-a[i]]+);
maxv=max(maxv,dp[j]);
}
int tmp;
for(int i=t-;i>=;--i)
if(dp[i]==maxv){
tmp=i;
break;
}
if(maxv==)
printf("Case %d: %d %d\n",++ca,,);
else
printf("Case %d: %d %d\n",++ca,dp[tmp]+,tmp+);
}
return ;
}
Jin Ge Jin Qu hao的更多相关文章
- 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 ...
- 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——[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
分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...
- UVa 12563 (01背包) Jin Ge Jin Qu hao
如此水的01背包,居然让我WA了七次. 开始理解错题意了,弄反了主次关系.总曲目最多是大前提,其次才是歌曲总时间最长. 题意: 在KTV房间里还剩t秒的时间,可以从n首喜爱的歌里面选出若干首(每首歌只 ...
- UVa 12563 Jin Ge Jin Qu hao【01背包】
题意:给出t秒时间,n首歌分别的时间a[i],还给出一首长度为678的必须唱的劲歌金曲,问最多能够唱多少首歌(只要最后时间还剩余一秒,都可以将劲歌金曲唱完) 用dp[i]代表花费i时间时唱的歌的最大数 ...
- UVA 12563 Jin Ge Jin Qu hao
dp-背包 开始用普通dp写了一发发现没法确定最大时间... 后来看到大牛机智的写法,嗯...dp表示当前状态能否成立:然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历. 具体的看代码吧.. ...
- UVA - 12563 Jin Ge Jin Qu hao (01背包变形)
此题应该注意两个点,首先背包容量应该缩减为t-1,因为最长的歌不超过三分钟,而劲歌金曲有678s,所以肯定要留出这个时间来.其次注意优先级,保证唱的歌曲数目最多,在此前提下尽可能的延长时间. 处理方法 ...
随机推荐
- crontab定时运行git命令 更新代码库
Q: http://stackoverflow.com/questions/7994663/git-push-via-cron I'm trying to run a git push fro ...
- Eclipse安装SVN插件的方法( 手动安装)
Eclipse Svn 插件CSDN下载地址:http://download.csdn.net/source/3143260 手动安装: 1.在Eclipse根目录下建一个任意文件夹(如plugin ...
- 纯互联网项目“失宠”乐博资本杨宁称今后只投O2O
从去年开始,我们接下来会进入全新的时代,就是智能一切的时代!过去的互联网都在电脑里,都在服务器里,包括现在移动云也是,大数据都是在服务器里面,真正我们身边的东西,智能含量是非常低的.包括你家洗衣机.冰 ...
- hihocoder 1084 扩展KMP && 2014 北京邀请赛 Justice String
hihocoder 1084 : http://hihocoder.com/problemset/problem/1084 北京邀请赛 Just String http://www.bnuoj.co ...
- ZOJ 2563 Long Dominoes(状压DP)
给定一个m*n的方格子,要求用3*1的骨牌去覆盖,骨牌可以用横放或者竖放,问最终有多少种放置方式,将其铺满. 分析:由于最多30行,每行最多9列,所以可以按行来dp,设计每行的状态从而进行转移,考虑每 ...
- iOS LLDB调试器
随着Xcode 5的发布,LLDB调试器已经取代了GDB,成为了Xcode工程中默认的调试器.它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能.LLDB为Xcode提供了底层调试环 ...
- Haxe - Actuate.Tween
方法解释: Actuate.tween( target : Dynamic , duration : Float , properties : Dynamic , ?overwrite : Bool ...
- Checked&Unchecked Exception
Java 中定义了两类异常: 1) Checked exception: 这类异常都是Exception的子类 .异常的向上抛出机制进行处理,如果子类可能产生A异常,那么在父类中也必须throws A ...
- 如何学习一个新的PHP框架
如今的PHP框架层出不穷,我不是这方面的专家,甚至不能熟练地使用其中的一种,所以我不做推荐,也不想讨论哪些算是框架哪些不算框架.这里我要讨论的是如何才能更快地开始使用某个新的框架. 首先你当然必须选择 ...
- Xcode插件开发
一.安装模板 1.git clone https://github.com/kattrali/Xcode-Plugin-Template.git 2.cd Xcode-Plugin-Template ...