• 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.
每首歌唱一次,在一定时间类,要求唱歌数量尽量多,时间尽量长。而且在最后一首唱完前,KTV不会停。
因此找出t-1时间内唱歌数最多为多少,再加上金曲的即可。(感觉思路一样,但就是一直不过 - - !!心塞塞)
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int V[55], num[10000], t, n;
int main()
{
int cas, tmp;
scanf("%d", &cas);
for(int k = 1; k <= cas; ++k)
{
memset(num, 0x8f, sizeof(num));
scanf("%d%d", &n, &t);
for(int i = 0; i < n; ++i) scanf("%d", &V[i]);
num[0] = 0; //其余初始化为负,使其从0开始计时
for(int i = 0; i < n; ++i)
for(int j = t - 1; j >= V[i]; --j)
num[j] = max(num[j], num[j - V[i]] + 1);
tmp = t-1;
for(int j= t - 1; j >= 0; --j)
if(num[j] > num[tmp]) //找出数量最大的,并且还能满足时间尽可能长
tmp = j;
printf("Case %d: %d %d\n", k, num[tmp] + 1, tmp + 678);//再加上金曲
}
return 0;
}