uva 12356 - Army Buddies



Description

???

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(?Š2?-Œé‡‘?›2). 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 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[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".


Rujia Liu‘s Present 6: Happy 30th Birthday to Myself

Special thanks: Md. Mahbubul Hasan, Feng Chen

题意:有一首劲歌金曲很长,最后要唱,在之前:给出最后剩t秒,n首歌,求最大能唱多少首,然后输出最长长度。

思路:01背包变形,前面的很好求,后面处理看代码。

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdlib.h>

using namespace std;

int w[55];

int dp[10000];
int mxt[105],mxl[105];
void solve(int ca,int n,int W){
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=W;j>=w[i];j--){
            if(~dp[j-w[i]])
                dp[j]=max(dp[j],dp[j-w[i]]+1);
        }
    }
    mxt[ca]=0;
    for(int j=W;j>=0;j--){
        if(dp[j]>mxt[ca]) {
            mxt[ca]=dp[j];
            mxl[ca]=j;
        }
    }
    if(mxt[ca]==0) mxl[ca]==0;
}

int main(){
    int T;
    scanf("%d",&T);
    for(int k=1;k<=T;k++){
        int n,t;
        scanf("%d%d",&n,&t);
        for(int i=0;i<n;i++){
            scanf("%d",&w[i]);
        }
        solve(k,n,t-1);
        printf("Case %d: %d %d\n",k,mxt[k]+1,mxl[k]+678);
    }
}

uva 12356 - Army Buddies

时间: 2024-11-12 15:35:51

uva 12356 - Army Buddies的相关文章

uva 12356 Army Buddies 树状数组解法 树状数组求加和恰为k的最小项号 难度:1

Nlogonia is fighting a ruthless war against the neighboring country of Cubiconia. The Chief General of Nlogonia's Army decided to attack the enemy with a linear formation of soldiers, that would advance together until conquering the neighboring count

uva 1416 Warfare And Logistics (最短路树)

uva 1416 Warfare And Logistics Description The army of United Nations launched a new wave of air strikes on terrorist forces. The objective of the mission is to reduce enemy's logistical mobility. Each air strike will destroy a path and therefore inc

UVA - 1494 Qin Shi Huang&#39;s National Road System (类次小生成树)

Description During the Warring States Period of ancient China(476 BC to 221 BC), there were seven kingdoms in China -- they were Qi, Chu, Yan, Han, Zhao, Wei and Qin. Ying Zheng was the king of the kingdom Qin. Through 9 years of wars, he finally con

UVA - 1416 Warfare And Logistics (最短路)

Description The army of United Nations launched a new wave of air strikes on terroristforces. The objective of the mission is to reduce enemy's logistical mobility. Each airstrike will destroy a path and therefore increase the shipping cost of the sh

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te

UVA 11014 - Make a Crystal(容斥原理)

UVA 11014 - Make a Crystal 题目链接 题意:给定一个NxNxN的正方体,求出最多能选几个整数点.使得随意两点PQ不会使PQO共线. 思路:利用容斥原理,设f(k)为点(x, y, z)三点都为k的倍数的点的个数(要扣掉一个原点O).那么全部点就是f(1),之后要去除掉共线的,就是扣掉f(2), f(3), f(5)..f(n).n为素数.由于这些素数中包括了合数的情况,而且这些点必定与f(1)除去这些点以外的点共线,所以扣掉.可是扣掉后会扣掉一些反复的.比方f(6)在f

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 401.Palindromes

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342 题目意思:给出一段字符串(大写字母+数字组成).判断是否为回文串 or 镜像串 or 回文镜像串 or 什么都不是.每个字母的镜像表格如下 Character Reverse Character Reverse Character Reverse A A M M Y Y B