Background: Tonight in TYVJ to participate in a game, did not expect a shameful kneeling. The first question of the Earth people know SPFA, the result I wrote a coordinate class DP also got 30 points ... Tragedy. The only consolation is that I used combinatorial mathematics to make the second question, laying the foundation for our school to have five people rushing into the first six. First, the second question is OK.
Title: Due to tyvj comparison pit, the title of the game is gone! Can only say the general meaning. Given n apples, the request is divided into 3 bags. The bag is disorderly, ask how many kinds of cases, and the K modulus.
Input interpretation: First line, enter two integers n,k
Output interpretation: The output is only one line, that is, the total number of scenarios to K modulo results.
Input Sample: 11 10000
Output Sample: 9525
Topic Analysis:
It is clear that each Apple has three possibilities, which are placed in the three-way bag. So the total number of n apples is 3^n.
We may wish to use the repulsion principle to classify all situations:
(1) When there are two bags for 0 o'clock. Then there will be 0, 0, all, 0, all, 0, all, 0, 3 cases. Obviously this should be considered a situation. The reason is three rather than six (see below), because when we put all the apples into a bag, it is obviously equivalent to placing an apple. There is no doubt that there is only one case for an apple.
(2) for the rest of the situation, we might as well put three bags according to the number of apples sorted. For example. It is clear that this set of numbers has six different sequences. That's what we're talking about in general.
So we can get the formula: ans= (3^n-3)/6+1. In fact, the use of division inverse can be further simplified, ask the students to think for themselves. (The explanation is here, the source code will not have to send it?) In fact, the code was swallowed by tyvj ... )
Back Gear | apple