UVA 12563 "Jin Ge Jin Qu hao" (背包)
debug了好一会,突然发现,输出错了,emmm.........
明天再写debug历程;
(PS:ipad debug是真的繁琐)
题意:

题解:
尽管题干中给的 t 的范围很大,但是 t ≤ 50*180+678;
int dp[maxn];///dp[i]:恰好唱i分钟时的最大曲目个数
AC代码:
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
#define memF(a,b,n) for(int i=0;i <= n;a[i++]=b);
const int maxn=1e5+; int n,T;
int t[];
int dp[maxn]; void Solve()
{
memF(dp,-,T);
dp[]=;
for(int i=;i <= n;++i)
{
for(int j=T-;j >= t[i];--j)
{
if(dp[j-t[i]] != -)
dp[j]=max(dp[j],dp[j-t[i]]+);
}
}
int ans=*max_element(dp,dp+T-);
for(int i=T-;i >= ;--i)
if(dp[i] == ans)///查找曲目数==ans的最长时间
{
printf("%d %d\n",dp[i]+,i+);
return ;
}
}
int main()
{
int test;
scanf("%d",&test);
for(int kase=;kase <= test;++kase)
{
scanf("%d%d",&n,&T);
for(int i=;i <= n;++i)
scanf("%d",t+i); printf("Case %d: ",kase);
Solve();
}
return ;
}
坑:注意读题,曲目数的优先级高于时间;
UVA 12563 "Jin Ge Jin Qu hao" (背包)的更多相关文章
- 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 ...
- uVa 12563 Jin Ge Jin Qu
分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...
- 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 ...
- 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
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- 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 (01背包变形)
此题应该注意两个点,首先背包容量应该缩减为t-1,因为最长的歌不超过三分钟,而劲歌金曲有678s,所以肯定要留出这个时间来.其次注意优先级,保证唱的歌曲数目最多,在此前提下尽可能的延长时间. 处理方法 ...
- Jin Ge Jin Qu hao UVA - 12563 01背包
题目:题目链接 思路:由于t最大值其实只有180 * 50 + 678,可以直接当成01背包来做,需要考虑的量有两个,时间和歌曲数,其中歌曲优先级大于时间,于是我们将歌曲数作为背包收益,用时间作为背包 ...
随机推荐
- C++中delete this
Is it legal (and moral) for a member function to say delete this? As long as you’re careful, it’s ok ...
- (五)IO流之ByteArrayInput/OutputStream
ByteArrayInputStream:是把字节数组当成源的输入流 String string="hello shanghai"; ByteArrayInputStream bi ...
- Kubernetes1.3新特性:支持GPU
(一) 背景资料 GPU就是图形处理器,是Graphics Processing Unit的缩写.电脑显示器上显示的图像,在显示在显示器上之前,要经过一些列处理,这个过程有个专有的名词叫" ...
- Directx11学习笔记【二十一】 封装键盘鼠标响应类
原文:Directx11学习笔记[二十一] 封装键盘鼠标响应类 摘要: 本文由zhangbaochong原创,转载请注明出处:http://www.cnblogs.com/zhangbaochong/ ...
- php json_encode输出为空问题
这种情况一般是json_encode序列化数组时出现错误,错误原因有很多,可以通过json_last_error函数来查看错误原因!!! 可能的原因 ------------------------- ...
- 2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server
题目描述 In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code ...
- JS 的私有成员为什么钦定了 #?
翻译自 tc39/proposal-class-fields 译者按:社区一直以来有一个声音,就是反对使用 # 声明私有成员.但是很多质疑的声音过于浅薄.人云亦云.其实 TC39 早就对此类呼声做过回 ...
- Cacti 加入多台主机带宽汇聚
前面我写了一个cacti加入主机带宽监控的博客.能够參考http://blog.csdn.net/dai451954706/article/details/35272465 .有时可能 ...
- java 简单实现FtpClient
1. 引入喜闻乐见的maven地址 <dependency> <groupId>commons-net</groupId> <artifactId>co ...
- python if 选择结构