Each song can only be sung once, and the middle cannot sing, so the state is assigned to 1, in order to distinguish the legal state and illegal state, in the most vocal repertoire conditions, leave time should be as late as possible.
State F[c] represents the singing time for the largest singing track of C
#include <bits/stdc++.h>using namespacestd;Const intMAXN = -;Const intMaxt = the*maxn+679;intF[maxt];Const intJinge =678;intMain () {//freopen ("In.txt", "R", stdin); intT scanf"%d",&T); intKas =0; while(t--){ intN,t; scanf"%d%d",&n,&t); intK =0; Memset (F,-1,sizeof(int)*t); f[0] =0; for(inti =0; I < n; i++){ intV scanf"%d",&V); for(intj = T1; J >= V; j--){ if(~f[j-v] && (F[j] < f[j-v]+1) ) {F[j]= f[j-v]+1; if(F[j] > F[k] | | (F[j] = = F[k] && k <j)) {k=J; } }}} printf ("Case %d:%d%d\n", ++kas,f[k]+1, K +Jinge); } return 0;}
UVA 12563 Jin Ge jin Qu [h] ao Jin Song (01 backpack)