Convert from WDD: http://blog.csdn.net/u010535824/article/details/38540835
Link: HDU 4778
Pressure DP
Use DP [I] to indicate the maximum value obtained from the I state selection to the end.
The Code also comes from WDD.
1 /************************************** * **************** 2 * File Name: b. CPP 3 * Author: kojimai 4 * creater time: on Wednesday, 5 seconds ******************************* * **********************/6/* 7, in a container, every second of the same-color gems can be combined into a magic stone. There is a certain number of gems in the bag. 8 * in a two-person game, each person puts all the gems in a package into the container every round. If this operation can get a magic stone, then we can perform another operation 9 * both of them adopt the most effective strategy and ask how much the difference between the magic stone obtained by the first hand and the magic stone obtained by the latter hand is 10 11 * Pressure DP, DP [I] indicates that the I state is the start, and the maximum value 12 * I (1 <j) can be obtained after the end is selected) = 0 indicates that J has already selected 13 * I & (1 <j) = 1 indicates that J is optional in the current state. The transfer equation is as follows: 14 ** DP [I] = max (DP [I], DP [I ^ (1 <j)] + CNT) at I ^ (1 <j) select J to obtain the CNT magic stone 15 ** DP [I] = max (DP [I],-dp [I ^ (1 <j)]). after J is selected, you cannot get the magic stone 16 */17 # include <cstdio> 18 # include <cstring> 19 # include <cmath> 20 # include <algorithm> 21 # include <Iostream> 22 using namespace STD; 23 # define fff-2333333324 int gem [22] [9]; // 25 int now [9] in each package; // The number of each gemstone in the current status is 26 int DP [1 <21]; // 1 indicates which digits are available, and 0 indicates that this digit has been selected, in this state, the maximum number of cases until the end is 27 int main () 28 {29 int G, B, S; 30 While (CIN> G> B> S) // G-colornum B-bag s-least31 {32 If (G + B + S = 0) 33 break; 34 memset (gem, 0, sizeof (GEM )); 35 For (INT I = 0; I <B; I ++) 36 {37 int X, Y; 38 scanf ("% d", & X ); 39 For (Int J = 0; j <X; j ++) // read the number of gems in each package 40 {41 Scanf ("% d", & Y); 42 gem [I] [Y] ++; 43} 44} 45 int all = (1 <B ); 46 DP [0] = 0; 47 for (INT I = 1; I <all; I ++) 48 {49 DP [I] = FFF; 50 memset (now, 0, sizeof (now); 51 for (Int J = 0; j <B; j ++) 52 {53 If (I & (1 <j )) = 0) // In the current I status, J is not optional, that is, J has already been selected, calculate the 54 remaining gems from all selected points {55 for (int K = 1; k <= g; k ++) 56 {57 now [k] = (now [k] + GEM [J] [k]) % s; 58} 59} 60} 61/* cout <"I =" <I <":" <Endl; 62 for (Int J = 1; j <= g; j ++) 63 cout <now [J] <''; 64 */int cnt = 0; 65 f Or (Int J = 0; j <B; j ++) 66 {67 If (I & (1 <j ))! = 0) 68 {69 CNT = 0; 70 for (int K = 1; k <= g; k ++) 71 {72 int T = now [k] + GEM [J] [k]; 73 CNT + = t/s; 74} 75 // cout <"J =" <j <"CNT =" <CNT <Endl; 76 if (CNT) 77 DP [I] = max (DP [I], CNT + dp [I ^ (1 <j)]); 78 else79 DP [I] = max (DP [I],-dp [I ^ (1 <j)]); 80} 81} 82 // cout <"I =" <I <"dp =" <DP [I] <Endl; 83} 84 cout <DP [All-1] <Endl; 85} 86 return 0; 87}
HDU 4778 gems fight! Pressure DP