First, note that it makes no sense to flip the same row or column for two or more (the best solution is always to either flip the row / column zero or once), and the order that we flip across rows or columns is irrelevant, so we can describe solution as a 2N bitmap. One bit per row and one bit per column. If we flip this row / column once, turn it off if we flip it to zero time.
So, we need to look for 2 ^ (2N) possible solutions, preferring solutions with a large number of zeros.
Secondly, note that for one solution there are four possible coin states:
- Coin did not flip (0 flip)
- The coin was flipped over by its line (1 flip)
- The coin was flipped over by its column (1 flip)
- The coin was flipped both its row and column (2 flip)
Note that states 1 and 4 result in the original value of the coin
Also note that state 2 and 3 result in the opposite initial coin value
Start by expressing the initial state of the coins as a binary matrix (B). A 2N-bit field as 2 binary vectors (R, C) and the total number of tails as a function of this f (B, R, C) and the total number of bits as a function of g ( V_1 , V_2 )
So your goal is to make f> = minimum while minimizing g.
Think that if we first correct our R configuration (which rows will be thrown), how can we solve the problem only for C (which columns will we flip)? In other words, consider the simpler problem of only allowing column flipping and not allowing line reversal. How would you solve this? (hint: DP) Can you redistribute this article to the full issue again?
source share