此题DP即可
设f[i][j]表示已经装了i张CD,当前CD还剩下j分钟的最大歌曲数目
#include<cstdio>
#include<algorithm>
using namespace std;
int a[21],f[21][21],n,t,m;
inline int read()
{
int x=0; char c=getchar();
while (c<'0' || c>'9') c=getchar();
while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x;
}
int main()
{
freopen("rockers.in","r",stdin);
freopen("rockers.out","w",stdout);
n=read(),t=read(),m=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int k=1;k<=n;k++)
for (int i=m;i>0;i--)
for (int j=t;j>=a[k];j--)
f[i][j]=max(f[i][j],max(f[i-1][t],f[i][j-a[k]])+1);
printf("%d
",f[m][t]);
return 0;
}