Problem of the day
Let 'N' = 3, 'M' = 3.
There are 27 possible final arrays.
10 of them are sorted in non-decreasing order: [ '0, 0, 0' ], [ '1, 1, 1' ], [ '2, 2, 2' ], [ '0, 1, 2' ], [ '0, 0, 1' ], [ '0, 1, 1' ], [ '0, 0, 2' ], [ '0, 2, 2' ], [ '1, 1, 2' ], [ '1, 2, 2' ].
Thus the probability needed is '(10 / 27) % (10^9 + 7) = 703703709'.
The first line of input contains a single integer 'T', which denotes the number of test cases.
Then 'T' test cases follow. For each test case:
The first and only line contains two integers, 'N' and 'M'.
For each test case, return the probability that 'A' is sorted in non-decreasing order, modulo 10^9 + 7.
You don’t need to print anything. Just implement the given function.
1 <= 'T' <= 10
2 <= 'N, M' <= 10^3
Time Limit: 1 sec
2
3 5
2 2
960000007
750000006
First test case:-
There are '5^3 = 125' possible final arrays.
Out of the arrays with 'A[ 0 ] = 0', exactly '15' are sorted in non-decreasing order.
For arrays with 'A[ 0 ] = 1', exactly '10' are sorted in non-decreasing order.
For arrays with 'A[ 0 ] = 2', exactly '6' are sorted in non-decreasing order.
For arrays with 'A[ 0 ] = 3', exactly '3' are sorted in non-decreasing order.
For arrays with 'A[ 0 ] = 4', exactly '1' is sorted in non-decreasing order.
Thus, the answer is '(35 / 125) % (10^9 + 7) = 960000007'.
Second test case:-
There are 4 possible final arrays.
3 of them are sorted in non-decreasing order: [ '0, 0' ], [ '0, 1' ], [ '1, 1' ].
Thus, the answer is '(3 / 4) % (10^9 + 7) = 750000006'.
2
25 43
60 29
43816143
973827568