Problem #511
✰ - click to bookmark
★ - in your bookmarks
Tags:
unlabeled
Many thanks to Clive Fraser for creating this problem!
A table T has a large number of rows and columns. Both rows and columns are numbered from 0. Each entry in the table is an integer. T(r,c) refers to the integer stored at row r and column c. We know just two of the integers in the table.
T(0,0) = 1 and T(0,1) = 2
However, there are three recurrence relations which can be used to calculate other entries in the table. We will refer to these as R1, R2 and R3. These are given below.
R1: T(r,c) = T(r-1,c) + T(r-1,c+1)
R2: T(r,c) = T(r-1,c-1) + 3T(r,c-1)
R3: T(r,c) = T(r+1,c-1) - T(r,c-1)
The following example uses these recurrence relations to calculate other entries in the table:
From R1: T(1,0) = T(0,0) + T(0,1) = 1 + 2 = 3
From R2: T(1,1) = T(0,0) + 3 x T(1,0) = 1 + 3 x 3 = 10
From R3: T(0,2) = T(1,1) - T(0,1) = 10 - 2 = 8
In a similar way we can calculate all of the other entries in the table.
In this problem you will be given a number of r,c pairs and are asked to calculate the corresponding values of T(r,c). As r and c get larger the values of T(r,c) increase very rapidly. Consequently you are asked to give all values of T(r,c) modulo 1000000007 (10^9 +7).
Input/Output description: The first line of the input data will consist of a single integer N for the number of r,c pairs. Each of the following N lines consists of two integers r and c. Your answer is the corresponding value of T(r,c) modulo 1000000007. Combine all of your answers into a single string, separated by spaces.
Example:
input:
8
1 1
6 5
86 55
691 777
8571 2374
77700 90318
858646 166555
1958435 7111728
answer:
10 1483776 658145257 423878584 322743277 947771964 407751001 725526492