Describe
Ghost Millet is very clever, because of this, he is very busy, often have the Commissioner of the car's special agent came to him to consult politics. One day, when he traveled in Xianyang, his friend told him that the largest auction house in Xianyang (Ju Bao) is going to hold an auction, in which one of the treasures aroused his great interest, that is no word heavenly book. However, his itinerary is very full, he has bought a long-distance coach to Handan, unfortunately, the departure time is at the end of the auction. So, he decided to prepare in advance, the number of his own gold and a small bag good, so that in his existing gold coins under the ability to pay, any number of gold coins he can use these closed a combination of good money for the bill. Ghost Valley is also a very frugal person, he tried to make himself in the premise of satisfying the above requirements, the use of the minimum number of bags, and no two money bags have the same number of gold more than 1. Suppose he had m gold coins, could you guess how many money bags he would use, and how many gold coins were in each bag?
Analysis
- May be a bit of water, but this problem does very little, or practice a better
- Consider the binary
- Any number can be added and obtained by a power of 2.
- Then the number of the M-gold coins into a few 2 powers can make up the number of any 1~m. But not necessarily, the rest of the money is split into a separate, the answer is the first one greater than M 2^n of the N. What if it's just finished? Because the last part can not be m, so still want to take m apart, the result is the same.
- Why is the binary not the other binary? Because any number can be added and obtained by a power of 2. But the rest is not necessarily.
Code
https://code.csdn.net/snippets/612326
Bzoj-1192-the money bag of ghost millet