Best-of Match Winner
Time limit0.5sMemory limit512 MB
Count the A/B game result strings where Bob reaches M wins to take the series, and Albert reaches N wins before Bob reaches N, modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Combinatorics, Math
- Solved
- No attempts yet
Problem
Albert and Bob often play board games and decide the winner with a best-of series.
An X-win series is a match format where the first person to win X games wins the series, and at most games are played. Board games between the two children never end in a draw. For example, when , the following results are possible. A means Albert won the game, and B means Bob won the game.
AAA: Albert wins the series 3-0. Games 4 and 5 are not needed, so they are not played.BAAA,ABAA,AABA: Albert wins the series 3-1. Game 5 is not needed, so it is not played.BBAAA,BAABA,BABAA,ABBAA,ABABA,AABBA: Albert wins the series 3-2.- Besides these 10 results, swapping A and B gives 10 more results where Bob wins the series.
After the matches, Bob says the following. The final winner of the -win series is Bob, who won games first. However, if the series had been an -win series, Albert would have won. In other words, Albert reached wins first, but Bob reached wins first and became the final winner. Of course, .
For example, when and , the only result is ABB, where Albert wins the first game and Bob wins the other two.
Another example is and , which has three possible results:
AABBB: In a 2-win series, Albert would have won at game 2. In a 3-win series, Bob is the final winner.ABABB: In a 2-win series, Albert would have won at game 3. In a 3-win series, Bob is the final winner.BAABB: In a 2-win series, Albert would have won at game 3. In a 3-win series, Bob is the final winner.
Given and , count the results in which Bob reaches wins and becomes the final winner, while Albert reaches wins first. The count can be very large, so print it modulo .
Input
The first line contains the number of test cases .
Each test case is given on one line with two integers and , separated by a space.
Output
For each test case, print the answer on its own line.