Problem J

Jin Ge Jin Qu [h]ao

(If you smiled when you see the title, this problem is for you ^_^)

For those who don't know KTV, see: http://en.wikipedia.org/wiki/Karaoke_box

There is one very popular song called Jin Ge Jin Qu(劲歌金曲). It is a mix of 37 songs, and is extremely long (11 minutes and 18 seconds)[1].

Why is it popular? Suppose you have only 15 seconds left (until your time is up), then you should select another song as soon as possible, because the KTV will not crudely stop a song before it ends (people will get frustrated if it does so!). If you select a 2-minute song, you actually get 105 extra seconds! ....and if you select Jin Ge Jin Qu, you'll get 663 extra seconds!!!

Now that you still have some time, but you'd like to make a plan now. You should stick to the following rules:

  • Don't sing a song more than once (including Jin Ge Jin Qu).
  • For each song of length t, either sing it for exactly t seconds, or don't sing it at all.
  • When a song is finished, always immediately start a new song.

Your goal is simple: sing as many songs as possible, and leave KTV as late as possible (since we have rule 3, this also maximizes the total lengths of all songs we sing) when there are ties.

Input

The first line contains the number of test cases T(T<=100). Each test case begins with two positive integersnt(1<=n<=50, 1<=t<=109), the number of candidate songs (BESIDES Jin Ge Jin Qu) and the time left (in seconds). The next line contains n positive integers, the lengths of each song, in seconds. Each length will be less than 3 minutes[2]. It is guaranteed that the sum of lengths of all songs (including Jin Ge Jin Qu) will be strictly larger than t.

Output

For each test case, print the maximum number of songs (including Jin Ge Jin Qu), and the total lengths of songs that you'll sing.

Sample Input

2
3 100
60 70 80
3 100
30 69 70

Output for the Sample Input

Case 1: 2 758
Case 2: 3 777

Explanation

In the first example, the best we can do is to sing the third song (80 seconds), then Jin Ge Jin Qu for another 678 seconds.

In the second example, we sing the first two (30+69=99 seconds). Then we still have one second left, so we can sing Jin Ge Jin Qu for extra 678 seconds. However, if we sing the first and third song instead (30+70=100 seconds), the time is already up (since we only have 100 seconds in total), so we can't sing Jin Ge Jin Qu anymore!

Bonus

Be sure to test your program with the data provided in our gift package.

Notes

[1] I know that there are Jin Ge Jin Qu II and III, and some other unofficial versions. But in this problem please forget about them.

[2] I know that most songs are longer than 3 minutes. But don't forget that we could manually "cut" the song after we feel satisfied, before the song ends. So here "length" actually means "length of the part that we want to sing".

题意:在一定的时间内连续唱歌,最后一首唱11分钟18秒的劲歌金曲,问最多能长多长时间。

思路:滚动数组,dp[i][j]表示唱i首歌,j分钟的情况是否存在。

AC代码如下:

#include<cstdio>
#include<cstring>
using namespace std;
int dp[51][9010],n,m,t,T;
void solve()
{ int i,j;for(i=n;i>=0;i--)for(j=m-1;j>=0;j--)if(dp[i][j]==1){ printf("Case %d: %d %d\n",t,i+1,j+678);return;}
}
int main()
{ int i,j,k,p;scanf("%d",&T);for(t=1;t<=T;t++){ scanf("%d%d",&n,&m);memset(dp,0,sizeof(dp));dp[0][0]=1;for(i=1;i<=n;i++){ scanf("%d",&k);for(j=m;j>=k;j--)for(p=i;p>=1;p--)if(dp[p-1][j-k]==1)dp[p][j]=1;}solve();}
}

Jin Ge Jin Qu hao - UVa 12563 dp背包相关推荐

  1. Jin Ge Jin Qu hao UVA - 12563 (劲歌金曲)01背包,求装入的东西最多(相同多时价值大)

    题目:白书p274 题意:  KTV里面有n首歌曲你可以选择,每首歌曲的时长都给出了. 对于每首歌曲,你最多只能唱1遍. 现在给你一个时间限制t (t<=10^9) , 问你在最多t-1秒的时间 ...

  2. DP 例9-5 Jin Ge Jin Qu hao UVA - 12563

    题意:KTV里面有n首歌曲你可以选择,每首歌曲的时长都给出了. 对于每首歌曲,你最多只能唱1遍. 现在给你一个时间限制t (t<=10^9) , 问你在最多t-1秒的时间内可以唱多少首歌曲num ...

  3. UVA 12563 Jin Ge Jin Qu hao 01背包变形

    基本的01背包,更新的时候保持背包里每一个元素的num最大然后time尽量长 CSDN也支持makedown了试一下 12563 Jin Ge Jin Qu hao (If you smiled wh ...

  4. UVA 12563 劲歌金曲 Jin Ge Jin Qu hao

    劲歌金曲 Jin Ge Jin Qu hao 题面翻译 (如果当你看到这个标题的时候笑了,那么这个问题是为你准备的ヽ( ̄▽ ̄)ノ) 如果问一个麦霸:"你在KTV里必唱的曲目有哪些?" ...

  5. 12563 - 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 th ...

  6. UVA12563: Jin Ge Jin Qu hao(类01背包)

    Problem J Jin Ge Jin Qu [h]ao (If you smiled when you see the title, this problem is for you ^_^) Fo ...

  7. UVA 12563 Jin Ge Jin Qu hao(多阶段决策问题,DP)

    题意:给出n首爱唱的歌,剩余t时间.由于ktv最后不会强制暂停你的歌曲,所以最后你可以点一首劲歌金曲,也就是最后可以加上678秒多唱一些时间.问在保证能唱的歌曲尽量多的情况下,唱歌的时间尽量长.输出最 ...

  8. uva 12563——Jin Ge Jin Qu hao

    题意:给出n首歌及每首歌的播放时间,然后在t秒内唱这些歌,最后的剩余时间要大于0: 思路:01背包问题,对于没次选择,只有取或不取两种状态,只需在这两种状态中找到最优的策略即可. code: #inc ...

  9. UVA 12563 Jin Ge Jin Qu hao

    dp-背包 开始用普通dp写了一发发现没法确定最大时间... 后来看到大牛机智的写法,嗯...dp表示当前状态能否成立:然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历. 具体的看代码吧.. ...

最新文章

  1. 软件设计最近发展趋势对话录
  2. TensorFlow 笔记6--迁移学习
  3. html邮箱地址的正则表达式,javascript写一个校验邮箱的正则表达式
  4. matlab表示时间集合,matlab集合操作
  5. 第n小的质数(信息学奥赛一本通-T1099)
  6. 1-java学习笔记
  7. 一个实用的String实现类(C++)
  8. My Data Sructure TemplatesClass
  9. No.025:Reverse Nodes in k-Group
  10. c++ 覆盖、重载与隐藏
  11. 与秦岭有关的诗词146首
  12. 大学生 生活小技巧:利用插件(Tampermonkey )学习网课 | 查题
  13. 下载!《Linux 命令行大全》pdf
  14. GWAS相关的曼哈顿图-SNP密度图
  15. 硬盘安装linux镜像文件iso安装,通过ISO文件硬盘安装Ubuntu系统
  16. 柏力纪德:网店开店之后怎么运营
  17. 在windows下安装pyLint,对python进行语法检查
  18. 高通芯片联机读取修改串码 meid ESN wifi 蓝牙 sn等参数的操作解析{二}
  19. u盘删除文件怎么恢复,误删了u盘文件怎么恢复
  20. C++ Qt自建网页浏览器

热门文章

  1. 转载:那些年他(她)们做过的“蠢事”
  2. 微信小程序支付功能用服务器吗,微信小程序 支付功能 服务器端(TP5.1)实现...
  3. 深入理解C与C++ (0.1)
  4. 产品经理懂点技术之:常见的网络传输方式
  5. 华科提出首个用于伪装实例分割的一阶段框架OSFormer
  6. es android,ES文件浏览器
  7. python销毁线程_Python 中的线程
  8. 悟空CRM-11.0正式开源发布!
  9. 如何保留优秀的程序员
  10. 为U盘安装即插即用的kali(linux)操作系统(超级详细~)