Los grouping backpack Valley P1757 Babel value of the packet backpack

Topic links: https://www.luogu.org/problem/P1757

Most basic backpack packet, the code here

#include <bits / STDC ++ H.>
 the using  namespace STD;
 const  int MAXN = 1E5 + 10 ;
 int DP [ 1010 ];
 int A [ 1010 ], B [ 1010 ], C [ 1010 ], D [ 1010 ], F [ 1010 ] [ 1010 ];
 int main () {
     int m, n-; CIN >> m >> n-;
     int NUM = 0 ; // save the number of groups 
    for ( int I = . 1 ; I <= n-; I ++ ) { 
        Scanf ( " % D% D% D" , & A [I], & B [I], & c [I]); 
        NUM = max (NUM, c [I]); 
        D [c [I]] ++; // [I] Group c, increasing the number of items 
        F [C [I]] [D [C [I]]] = I; // first number of the sequence number is the number of groups 
    }
     for ( int I = . 1 ; I <= NUM; I ++ ) { // the number of groups enumerated 
        for ( int J = m; J> = 0 ; J, ) {
             for ( int K = . 1 ; K <= D [I]; K ++) { // sequentially enumeration of several of the group i 
                IF (J> = a [F [i] [K]]) 
                DP [J] = max (DP [J], DP [JA [F [i] [K]]] +b[f[i][k]]);
            }
        } 
    }
    cout<<dp[m]<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/qingjiuling/p/11354869.html