HDU-1799 (combination recurrence formula), hdu-1799 Recurrence Formula
HDOJ-1799-Fighting_Dream
M-brute force solution and table Creation
Time Limit:1000 MS
Memory Limit:32768KB
64bit IO Format:% I64d & % I64u
Description
We know that in programming, we often need to consider the time complexity, especially for the loop. For example,
If
For (I = 1; I <= n; I ++) OP;
N OP operations are performed.
Fori = 1; I <= n; I ++)
For (j = I + 1; j <= n; j ++) OP;
Then, n * (n-1)/2 OP operations are performed.
Now we know that there are m-layer for loop operations, and the starting value of each for variable is the starting value of the previous variable + 1 (the starting value of the first variable is 1 ), the end value is an input n, and the total calculation amount of the OP is asked.
Input
There are T group cases, T <= 10000. Each case has two integers, m and n, 0 <m <= 2000, 0 <n <=.
Output
For each case, output a value, indicating the total calculation amount. Maybe this number is large, you only need to output the remainder except 1007.
Sample Input
21 32 3
Sample Output
33
Question Analysis:
Note that the cyclic value is C (n, m) = n! /(N-m )! * M !), The formula cannot be used directly because the n value is too large.
Recursive Formula for composite mathematics: C (n, m) = C (n, m) + C (N-1 m-1). Once you know this problem, you can solve it.
Note:
Full Sorting Problem, C (n, m) = n! /(M! * (N-m )!)
However, considering that n is too large, this method cannot be used.
The combination formula C (n, m) = C (n-1, m) + C (N-1 m-1) can be used)
C (n, 1) = n; C (n, n) = 1; C (n, 0) = 1;
AC code:
# Include <stdio. h> int c [2001] [2001]; void juge () {for (int I = 1; I <= 2000; I ++) {c [0] [0] = 1; c [I] [0] = 1; for (int j = 1; j <= 2000; j ++) c [I] [j] = (c [I-1] [j] + c [I-1] [j-1]) % 1007; // combination formula }}int main () {int T, n, m; juge (); scanf ("% d", & T); while (T --) {scanf ("% d", & m, & n); printf ("% d \ n", c [n] [m]) ;}}