The Return of the Tteokfire
Time limit1sMemory limit128 MB
Count sequences of M daily bowl counts summing to N, where the first M-1 counts are positive and the M-th is zero.
- Level
Medium7 of 10
- Topics
- Combinatorics, Math, Dynamic programming
- Solved
- No attempts yet
Problem
A Tteokfire stays young by eating tteokguk, the Korean rice cake soup.
A Tteokfire ages one year for every bowl of tteokguk it eats. Digestion is instant, so it can eat as many bowls in one day as it likes. In exchange, a Tteokfire that goes a single day without tteokguk dies that day, no matter how much it ate before.
Didi knows only that one Tteokfire died on day at age . Didi wants to count how many ways that Tteokfire could have aged, but the count grows out of hand as the age rises, so counting by hand is hopeless.
A Tteokfire starts at age 0. One way of aging is the list of bowl counts for day 1 through day in order, and two ways are different when the count differs on at least one day. The Tteokfire ate nothing on day , which is why it died that day.
For equal to 3 and equal to 3 there are two ways: 1 bowl on day 1, 2 bowls on day 2 and 0 bowls on day 3, or 2 bowls on day 1, 1 bowl on day 2 and 0 bowls on day 3.
Input
The first line has the number of test cases ().
Each of the next lines has two integers () and (), separated by a space.
Output
For each test case, print the number of ways of aging modulo 100007 on its own line. Note that 100007 is not a modulus you see often.