Question: calculate the number of paths from (0, 0) to (n, 0). You can go up or down or straight down each time. (Cannot go to the negative area)
Analysis: combination, Count, qataran number, and big integer.
Because it cannot go to the negative area, the increase and the decrease must be equal at this time, and the increase Count must be no less than the decrease count at any time.
From this we can see that the rise and fall are the legal matching of the brackets mentioned above, and the enumerated numbers of all the rise and fall are:
F (n) = Σ (C (n, 2 * I) * CI:
C (n, 2 * I) is the number of solutions with I increase and I decrease in N routes, CI is the legal combination of I increase and I decrease (internal ).
Simplification: F (n) = Σ (C (n, 2 * k) * C (2 k, k)/(k + 1 ));
Set: B (K) = C (n, 2 * k) * C (2 k, k)/(k + 1 );
Recursive relationship: B (K) = B (k-1) * (n-2 * k + 2) * (n-2 * k + 1)/(K * (k + 1 ));
Use the above recursive relationship calculation.
Note: It seems that Java's large numbers are faster to use than parse.
#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;int C[4808] = {0};int ans[4808];int main(){int n;while (~scanf("%d",&n) && n) {memset(C, 0, sizeof(C));memset(ans, 0, sizeof(ans));C[0] = 1;ans[0] = 1;for (int i = 1 ; 2*i <= n ; ++ i) {for (int j = 0 ; j < 4800 ; ++ j)C[j] *= (n-2*i+2)*(n-2*i+1);for (int j = 0 ; j < 4800 ; ++ j) {C[j+1] += C[j]/10;C[j] %= 10;}for (int j = 4799 ; j >= 0 ; -- j) {C[j-1] += C[j]%((i+1)*i)*10;C[j] /= ((i+1)*i);}for (int j = 0 ; j < 4800 ; ++ j)ans[j] += C[j];for (int j = 0 ; j < 4800 ; ++ j) {ans[j+1] += ans[j]/10;ans[j] %= 10;}}int end = 99;while (!ans[end]) -- end;while (end >= 0) printf("%d",ans[end --]);printf("\n");}return 0;}
Ultraviolet A 1478-Delta Wave