CodeCraft-20 (Div. 2) E (like pressure DP)

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 typedef struct node{
 5     int val;
 6     int w[10];
 7 }srt;
 8 srt a[100007];
 9 bool cmp(srt a,srt b){
10     return a.val>b.val;
11 }
12 long long dp[100007][130];
13 int main(){
14     ios::sync_with_stdio(false);
15     cin.tie(NULL);
16     cout.tie(NULL);
17     int n,p,kk;
18     cin>>n>>p>>kk;
19     for(int i=1;i<=n;++i)
20         cin>>a[i].val;
21     for(int i=1;i<=n;++i)
22         for(int j=1;j<=p;++j)
23             cin>>a[i].w[j-1];
24     Sort (A + . 1 , A + . 1 + n-, CMP); // in accordance with a descending order contribution cheerleaders, behind only as players team members, because certain cheerleader p + kk produced one in the front 
25      Memset (DP , 0xCF , the sizeof (DP)); // initialize to a small negative number, so the minimum value of an untreated state 
26 is      DP [ 0 ] [ 0 ] = 0 ;
 27      for ( int I = . 1 ; I <= n-; ++ I) {
 28          for ( int J = 0 ; J < . 1 << P; ++ J) {
 29              for ( int K = 0 ; K <P; ++k)
 30                  IF (J & ( . 1 << k)) // person i fill the k-th position 
31 is                      DP [i] [J] = max (DP [i] [J], DP [I- . 1 ] [J ^ ( . 1 << K)] + A [I] .W [K]); // updates the maximum 
32              int MX = I- . 1 ; // have cheerleaders number 
33 is              for ( int K = 0 ; K <P; ++ K)
 34 is                  IF (J & ( . 1 << K))
 35                      the MX; // some team members as 
36              IF (MX <KK) // cheerleading still open 
37                 DP [I] [J] = max (DP [I] [J], DP [I- . 1 ] [J] + A [I] .val); // update the maximum value of 
38 is              the else 
39                  DP [I] [J ] = max (DP [I] [J], DP [I- . 1 ] [J]); // pushed back 
40          }
 41 is      }
 42 is      COUT << DP [n-] [( . 1 << P) - . 1 ] ;
 43 is      return  0 ;
 44 is }

 

Guess you like

Origin www.cnblogs.com/ldudxy/p/12426162.html