Topic Description:
A coin-flipping game, there are N (n <=10000) line coins, each line has nine coins, lined up into a n*9 square, some coins face up, some negative face up. Every time we can turn a whole line or a whole list of all the coins, how to turn, so that the face on the top of the coin as much as possible (flipping coins no limit).
Thinking Analysis:
Enumeration of 2^9 species columns.
Traverse N Line, if a row is facing up less, turn it on; if the front face up more, do not turn
Write down the methods that make the most positive
Time Consuming O (2^9 * N)
This gets the optimal solution. The efficiency of the bitwise operation is still very high.
For each column, it is represented by a 9-digit number, with a total of n
Then facilitate all 9-bit states, (000000000)-(111111111) (binary)
For each state, it is assumed to be k if the value of n is different or, after each addition, to sum up all 1 values, if K is less than 5 k=9-k.
Add all k to the N number and get the final sum.
To find out all the cumulative sum and the largest, that is, the front facing the number of coins as much as possible.
The method of row is respectively the 8-bit state of the optimal solution and the corresponding number of different or after sum and K is less than 5.