Trigger a coin

Source: Internet
Author: User

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.

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.