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 <iostream>
#include <string.h>
using namespace std;
const int MAX = * * + ;
struct Node {
int n, t; bool operator<(const Node &rhs) const {
return n < rhs.n ||
n == rhs.n && t < rhs.t;
}
}d[MAX]; int main() {
int n,cas,t,ti;
cin >> cas;
for (int cass = ; cass <= cas; ++cass) {
cin >> n >> t;
memset(d, , sizeof(d));
for (int i = ; i <= n; ++i) {
cin >> ti;
for (int v = t; v > ti; --v) { //0,1背包,滚动数组
Node tmp;
tmp.n = d[v - ti].n + ;
tmp.t = d[v - ti].t + ti;
if (d[v] < tmp)
d[v] = tmp;
}
}
printf("Case %d: %d %d\n", cass, d[t].n + , d[t].t + ); //最后金曲也要算进去
}
}

UVA - 12563 Jin Ge Jin Qu hao (01背包)的更多相关文章

  1. UVA12563Jin Ge Jin Qu hao(01背包)

    紫书P274 题意:输入N首歌曲和最后剩余的时间t,问在保证能唱的歌曲数目最多的情况下,时间最长:最后必唱<劲歌金曲> 所以就在最后一秒唱劲歌金曲就ok了,背包容量是t-1,来装前面的歌曲 ...

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

  3. uVa 12563 Jin Ge Jin Qu

    分析可知,虽然t<109,但是总曲目时间大于t,实际上t不会超过180*n+678.此问题涉及到两个目标信息,首先要求曲目数量最多,在此基础上要求所唱的时间尽量长.可以定义 状态dp[i][j] ...

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

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

  6. UVa 12563 (01背包) Jin Ge Jin Qu hao

    如此水的01背包,居然让我WA了七次. 开始理解错题意了,弄反了主次关系.总曲目最多是大前提,其次才是歌曲总时间最长. 题意: 在KTV房间里还剩t秒的时间,可以从n首喜爱的歌里面选出若干首(每首歌只 ...

  7. Jin Ge Jin Qu hao UVA - 12563 01背包

    题目:题目链接 思路:由于t最大值其实只有180 * 50 + 678,可以直接当成01背包来做,需要考虑的量有两个,时间和歌曲数,其中歌曲优先级大于时间,于是我们将歌曲数作为背包收益,用时间作为背包 ...

  8. 一道令人抓狂的零一背包变式 -- UVA 12563 Jin Ge Jin Qu hao

    题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  9. 【紫书】(UVa12563)Jin Ge Jin Qu hao

    继续战dp.不提. 题意分析 这题说白了就是一条01背包问题,因为对于给定的秒数你只要-1s(emmmmm)然后就能当01背包做了——那1s送给劲歌金曲(?).比较好玩的是这里面dp状态的保存——因为 ...

随机推荐

  1. Wannafly #4 F 线路规划

    数据范围252501 劲啊 Q国的监察院是一个神秘的组织. 这个组织掌握了整个Q国的地下力量,监察着Q国的每一个人. 监察院一共有N个成员,每一个成员都有且仅有1个直接上司,而他只听从其上直接司的命令 ...

  2. noip寻找道路

    题目描述 在有向图G 中,每条边的长度均为1 ,现给定起点和终点,请你在图中找一条从起点到终点的路径,该路径满足以下条件: 1 .路径上的所有点的出边所指向的点都直接或间接与终点连通. 2 .在满足条 ...

  3. 景深(Depth of Field)

    http://www.cnblogs.com/cxrs/archive/2013/03/22/DepthOfFeild.html 景深(Depth of Field) 什么是景深? 所谓景深,就是当焦 ...

  4. JUnit手记

    BeforeClass全局只执行一次初始化: Before,每个用例(测试方法)都会走一次: After/AfterClass以此类推

  5. BZOJ4003:[JLOI2015]城池攻占

    浅谈左偏树:https://www.cnblogs.com/AKMer/p/10246635.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php? ...

  6. from selenium.webdriver.support.ui import Select

    from selenium.webdriver.support.ui import Select Select(d.find_element_by_id(u'key_开户行')).first_sele ...

  7. Poj 2853,2140 Sequence Sum Possibilities(因式分解)

    一.Description Most positive integers may be written as a sum of a sequence of at least two consecuti ...

  8. 2006浙大火星A+B

    题目描述:     读入两个不超过25位的火星正整数A和B,计算A+B.需要注意的是:在火星上,整数不是单一进制的,第n位的进制就是第n个素数.例如:地球上的10进制数2,在火星上记为“1,0”,因为 ...

  9. Cypress USB3014 C++DLL 导入问题

    VS2017编译cpp工程出现问题 硬件型号:芯片版本 Cypress FX3 USB3014(和芯片无关)) 重现步骤: 1.解压 FX3_SDK_Windows_v1.3.3.exe 2.VS20 ...

  10. 使用showInputDialog显示输入框

    ------------------siwuxie095                             工程名:TestJOptionPane 包名:com.siwuxie095.showd ...