Poj 1185 Artillery Position
Chinese questions.
Solution: You can see from the question that the status of each row is only related to the first two rows. N <100, m <= 10 is known. Obviously, m can be compressed, and the status of each position in M can be expressed as 0, 1. Therefore, the total state of M can be expressed by the decimal number converted from the binary value with the length of M. The calculation shows that there are not many legal states, because two soldiers in the same row cannot attack each other.
Key code for finding a valid status:
REP(i, (1<<m)) { p = i; if(((p << 1) & i) || ((p << 2) & i)) continue; num[sum] = 0; while(p) {num[sum] += (p&1); p >>= 1;} status[sum++] = i;}
Status [p] = I indicates that the valid status of the nth P is I. Num [I] = A, indicating that a artillery was deployed when the status was I.
After the data is processed, the status 0 of the current checker indicates P and 1 indicates H. Chess [I] = s indicates the status of row I is S.
Set DP [I] [J] [k] to indicate that the status of row I is J and that of row I-1 is K.
DP [I] [J] [k] = max (DP [I-1] [k] [p]) + num [J];
Yes (status [J] & status [k]) = 0
(Status [J] & chess [I]) = 0 & (status [k] & chess [I-1]) = 0)
(Status [k] & status [p]) = 0 & (status [J] & status [p]) = 0)
For DP [0] [J] [K], it is provided separately during initialization. DP [0] [J] [k] = num [J]; (if it is not in conflict with the original Board)
PS: The pressure DP is also a God-class topic. It must be done well after the poj training program is completed! I will start to dig into poj tomorrow. Come on !!