题目:白书p274

题意: 
KTV里面有n首歌曲你可以选择,每首歌曲的时长都给出了. 对于每首歌曲,你最多只能唱1遍. 现在给你一个时间限制t (t<=10^9) , 问你在最多t-1秒的时间内可以唱多少首歌曲num , 且最长唱歌时间是多少time (time必须<=t-1) ? 最终输出num+1 和 time+678 即可. 
注意: 你需要优先让歌曲数目最大的情况下,再去选择总时长最长的. 
解析: 
每种歌曲只能用一次,所以是比较水的01背包题 
最后枚举找到最大曲目数量并且时间尽量靠后即可

题目中t的范围是1e9但实际的t不会超过10000,这就可以转化为01背包问题

(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) — 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.

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 integers n, t (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 — 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”.

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.

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!

Sample Input

2

3 100

60 70 80

3 100

30 69 70

Sample Output

Case 1: 2 758

Case 2: 3 777

#include<stdio.h>
#include<string.h>
#include<map>
#include<algorithm>
using namespace std;
int t,m,n;
int dp[110];
int w[10000010];
int main()
{int k=1;scanf("%d",&t);while(t--){scanf("%d%d",&m,&n);for(int i=0; i<m; i++)scanf("%d",&dp[i]);memset(w,-1,sizeof(w));w[0]=0;/**care*/for(int i=0; i<m; i++)for(int j=n-1; j>=dp[i]; j--)w[j]=max(w[j],w[j-dp[i]]+1);int ans=0,sum;for(int i=0;i<=n;i++){if(ans<=w[i]){ans=w[i];sum=i;}}printf("Case %d: %d %d\n",k++,ans+1,sum+678);}return 0;
}

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

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

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

  2. Jin Ge Jin Qu hao - UVa 12563 dp背包

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

  3. uva 12563 劲歌金曲

    先介绍自己写的,比较循规蹈矩的方法.dp(i,j)表示必须在j时间内结束,在i,i+1,,,,n首歌中选择,可以唱的最大歌曲数 (包含jq) sing(i,j)表示在这个状态.歌曲数取最大的情况下,可 ...

  4. uva 12563劲歌金曲

    动态规划例题 在规定的时间内要唱最多的歌但最后要留出时间唱劲歌金曲,求唱最多的歌的个数以及此时的最长时间 源码 #include<stdio.h> #include<string.h ...

  5. UVA - 12563 劲歌金曲(DP 01背包)

    题目 KTV里面有n首歌曲你可以选择,每首歌曲的时长都给出了(每首歌时长不超过3min). 对于每首歌曲,你最多只能唱1遍. 现在给你一个时间限制t (t<=10^9) , t实际不会超过(18 ...

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

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

  7. UVA 12563 劲歌金曲(滚动数组)

    这道题练习了滚动数组,不过跟0-1背包问题有点不同,为了记录准确时间,通过设置条件把无用状态剔出来,消除了错误时间,f[i]表示i时,唱了多少首歌. #include<bits/stdc++.h ...

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

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

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

最新文章

  1. 图解MySQL数据库的安排和把持-1
  2. Python列表对象的sort()方法排序
  3. Update: OCS 2007 R2 (RTM) Download and Documentation
  4. 神经网络中的矩阵求导及反向传播推导
  5. 分页缓冲池如何关闭_线程池没你想的那么简单
  6. 严选前端全栈工程师学习笔记
  7. java集合浅谈(一)
  8. Devuan Jessie beta 释出
  9. android 访问服务器sql_XSS 攻击、CSRF 攻击、SQL 注入、流量劫持(DNS 劫持、HTTP 劫持)—— 浏览器安全
  10. “编程能力差,90%输在了数学上!”CTO:多数程序员都是瞎努力!
  11. python中类的定义_python中类的概念
  12. atitit.颜色查找 根据范围 图像处理 inRange
  13. Pandas库的基本使用方法
  14. 安装oracle数据库过程中系统表空间,Oracle数据库安装及配置
  15. 2022-2028年中国幼儿园露天游乐设备行业市场专项调查及投资前景分析报告
  16. 从小米雷军的逆天布局你能读出什么?
  17. 2015-点餐系统(服务器)
  18. 电脑提高或开启高性能模式
  19. Android8.0 SystemUI 状态栏信号图标
  20. 3GPP TS 23501-g51 中英文对照 | 5.2.1 General

热门文章

  1. WireShark抓DNS请求和回复数据报的分析
  2. Android之Android Studio 快捷键整理分享
  3. Android之ADB常用命令
  4. Android之Broadcast, BroadcastReceiver(广播)
  5. 查询工资最低的3名员工的职工工号、姓名和收入_普法课堂|你有多久没有收到工资条了?...
  6. 已婚男人看见美女都这个眼神?
  7. 如何巧妙拒绝老同学借钱?哈哈哈哈哈......
  8. 如何判断一个人是不是值得深入交流?
  9. 你家猫砸东西是不是也专挑贵的砸?
  10. AI人工智能资料分享来袭,还不快来!