UVA Songs

Solution

It is easy to think of this is a 01 backpack, because even leave time, it first time minus 1, plus Songs after 678 seconds, the other just fine attention to detail.

Code

#include<bits/stdc++.h>
using namespace std;
int n,t,w[100005],a[100005],f[100005];
int main(){
    freopen("a.in","r",stdin);
    int T,cnt=0;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&t);
        --t;
        fill(f,f+t+1, 0 ); // remember to +1 or less cleared F [T] 
        Fill (A, A + T + . 1 , 0 );
         for ( int I = . 1 ; I <= n-; I ++ ) 
         Scanf ( " % D " , & W [I]);
         for ( int I = . 1 ; I <= n-; I ++ )
          for ( int J = T; J> = W [I]; J, )
           IF (F [J] <F [ JW [I]] + . 1 ) 
           F [J] = F [JW [I]] + . 1 , A [J] = A [JW [I]] + W [I]; // make the total length because even the most long
           else
           IF (F [J] == F [JW [I]] + . 1 && A [J] <A [JW [I]] + W [I]) // while recording the total length 
            A [J] = A [JW [ I]] + W [I]; 
        the printf ( " Case% D: D% D% \ n- " , CNT ++, F [T] + . 1 , A [T] + 678 ); // finally re + +1 678 
    } 
}

 

Guess you like

Origin www.cnblogs.com/coder-cjh/p/11409879.html