Description:
In a coin flip game, there are n (n <= 10000) rows of coins, each row has nine coins, arranged in a matrix of N * 9, some coins face up, and some sides face up. We can flip all the coins in a row or a whole column each time. How can we flip as many coins as possible on the front (there is no limit on the number of coins ).
Train of Thought Analysis:
Enumeration 2 ^ 9 types of column turning.
Traverse n rows. If a row is less on the front, flip it over. If there are more on the front, do not flip
Write down the methods that make the most positive
Time consumed O (2 ^ 9 * n)
This results in the optimal solution. Bit operation efficiency is still very high.
Each column is represented by a number of 9 bits, with a total of N
Then all the nine-bit states are facilitated, (000000000)-(111111111) (Binary)
For each status, it is different from the N number. If K is less than 5, K = 9 K.
Accumulate all K of N to get the final sum.
Find the number of accumulated and largest coins in all States, that is, the number of coins facing up as much as possible.
The crosstab chart shows the 8-bit state of the optimal solution and whether each number is different or the accumulated number and K is less than 5.