Title Description
Description
You have just inherited the copyright of the <= N (1 n <= 20) song recorded by the popular "Broken Gong Rock" band. You are going to select some songs from which to release m (1 <= m <= 20) CD. Each CD can hold up to T (1 <= T <= 20) minutes of music and one song cannot be divided on two CDs.
Unfortunately you are a classical music fan, do not know how to determine the artistic value of these songs. So you decide to choose according to the following criteria:
1. Songs must appear on the CD in chronological order of creation.
2. Select the number of songs as much as you can.
Enter a description
Input Description
First line: three integers: N, T, M.
Second line: n integers that represent the length of each song, in chronological order of creation.
Output description
Output Description
An integer that represents the maximum number of songs that can be loaded into the M CD disc.
Sample input
Sample Input
4 5 2
4 3 4 2
Sample output
Sample Output
3
/*deformed knapsack problem f[j][k] indicates that the current song is loaded to the J CD, and the maximum number of songs that can be installed when installed in K capacity is f[j][k]=f[j][k-a[i]]+1 when the first J CD is installed, and when the second is not loaded, it should be loaded into the first j-1, that is f[ J][k]=f[j-1][t]+1. */#include<iostream>#include<cstdio>#include<algorithm>#defineM 22using namespacestd;intn,m,t;intT[m];intF[m][m];intMain () {scanf ("%d%d%d",&n,&t,&m); for(intI=1; i<=n;i++) scanf ("%d",&T[i]); for(intI=1; i<=n;i++) for(intj=m;j>=1; j--) for(intk=t;k>=t[i];k--) {F[j][k]=max (f[j][k],f[j][k-t[i]]+1); F[J][K]=max (f[j][k],f[j-1][t]+1); } printf ("%d", f[m][t]); return 0;}
View Code
"Broken Gong Rock" band (Codevs 1444)