#P15612. [ICPC 2021 Jakarta R] Feeder Robot
[ICPC 2021 Jakarta R] Feeder Robot
题目描述
Vincent switches his retirement plan from raising horses and goats into raising chickens. He procures chickens and lays each of them into their own coop (hen house). The coops are placed on a single line numbered sequentially from at the left-most to at the right-most.
To make his retirement blissful (or at least he thought), Vincent buys a feeder robot. This feeder robot is to be loaded with pellets and it will distribute them for the chickens to feed on. The feeder robot will move from one coop to an adjacent coop and distribute pellet to each coop it visits. If a coop is visited times by the robot including the robot's initial position, then it will get pellets.
However, Vincent has just noticed that he cannot control how the robot moves. Let the robot be in front of coop . If the robot still has pellets to distribute, it will move to an adjacent coop (coop or ) at random and distributes pellet to that coop. This process repeats until the robot has no more pellets to distribute. Note that if , then the robot will move to coop ; similarly, if , then the robot will move to coop .
Since Vincent dislikes you even though you are his only friend, he challenges you to a problem. The challenge is to count how many possible pellets distributions are there if the robot starts at coop . A pellets distribution is defined as a tuple where is the final position of the robot and is the number of pellets coop gets. Two distributions are different if and only if the final position of the robot differs or there is a coop that gets a different number of pellets. The robot's movement or the order when the coop gets a pellet does not matter.
Since the output can be quite big, Vincent requires you to give him the non-negative remainder when the output is divided by . Believing that you cannot solve it, Vincent agrees to award you with a hefty reward if you managed to solve his challenge.
For example, let , , and . In this example, there are different pellets distributions.
- : The robot ends at coop and the number of pellets each coop gets is . The robot's movement that causes this distribution is: The robot starts at coop and distributes pellet to coop ; it moves to coop and distributes pellet to coop ; it moves to coop and distributes pellet to coop . In a simple notation, the robot's movement is
- : The robot ends at coop and the number of pellets each coop gets is . The robot's movement is .
- : The robot ends at coop and the number of pellets each coop gets is . The robot's movement is .
输入格式
Input contains three integers (; ; ) representing the number of coops, the number of pellets, and the starting position of the feeder robot, respectively.
输出格式
Output contains an integer in a line representing the non-negative remainder when the number of different pellets distributions is divided by .
4 3 2
3
3 5 2
3
3 6 2
6
提示
Explanation for the sample input/output #2
There are different pellets distributions in this case.
- : The robot ends at coop and the number of pellets each coop gets is . The robot's movement is $2 \rightarrow 1 \rightarrow 2 \rightarrow 1 \rightarrow 2$.
- : The robot ends at coop and the number of pellets each coop gets is . The robot's movement is $2 \rightarrow 3 \rightarrow 2 \rightarrow 3 \rightarrow 2$.
- : The robot ends at coop and the number of pellets each coop gets is . The robot's movement is $2 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 2$ or $2 \rightarrow 3 \rightarrow 2 \rightarrow 1 \rightarrow 2$; both of them give the same distribution, i.e. the robot ends at the same coop and each coop gets the same number of pellets in both distributions.
Explanation for the sample input/output #3
There are different pellets distributions in this case: , , , , , and .