Flip the coin small fun problem _ game

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.