#P15625. [ICPC 2022 Jakarta R] Sharing Bread
[ICPC 2022 Jakarta R] Sharing Bread
题目描述
There are toasters, numbered from to , from left to right. Initially, each toaster has a single piece of bread in it. There are people, numbered from to , who are one by one looking for bread among the toasters, starting from person , person , and so on.
Person starts looking from toaster () and keeps going right until they found a toaster with a piece of bread in it. In other words, person is looking for the smallest such that and toaster contains bread. If such a toaster exists, then person will take the bread from that toaster and leave; the toaster becomes empty afterward. If such a toaster does not exist, then person will leave empty-handed.
A starting sequence is fair if person starts looking from toaster and does not leave empty-handed, for all . Out of all possible starting sequences, determine how many of them are fair modulo .
输入格式
Input consists of two integers () in a single line representing the number of toasters and the number of people, respectively.
输出格式
Output an integer in a single line representing the number of fair starting sequence modulo .
4 3
50
10 1
10
2 2
3
提示
Explanation for the sample input/output #1
One of the possible fair starting sequences is . First, person starts looking from toaster and takes the bread from toaster . Then, person starts looking from toaster and takes the bread from toaster . Finally, person will start looking from toaster , which is currently empty. Person moves to toaster and takes the bread from toaster . Since each person gets a piece of bread, the starting sequence is fair.
Another example of fair starting sequences are , , , and . Some of the possible starting sequences that are not fair are , , , and .
Explanation for the sample input/output #2
All starting sequences are fair.
Explanation for the sample input/output #3
The only starting sequence that is not fair is . Person starts looking from toaster and takes the bread from toaster . Then, person starts looking from toaster , which is currently empty. Since there is no more toaster to the right of toaster , person will leave empty-handed.