标签:style class blog code ext color
#include <stdio.h> const int N = 1000001; const long long MOD = (long long)1E9 + 7LL; long long g; void extGCD(long long a,long long b,long long &x,long long &y) { if(b == 0) { x = 1, y = 0; g = a; return ; } extGCD(b, a % b, y, x); y -= a / b * x; } long long modReverse(long long a, long long n) { long long x, y; extGCD(a, n, x, y); return (x + n) % n; } long long Catalan[N]; //0 1 2 3 4 5 6 7 8 9 10 11 12 void genCatalan() //1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 { Catalan[0] = Catalan[1] = 1LL; for (int i = 2; i < N; i++) { long long tmp = modReverse(i+1LL, MOD); Catalan[i] = Catalan[i - 1] * ((i<<2) - 2) % MOD * tmp % MOD; } } int main() { genCatalan(); int T, num; scanf("%d", &T); for (int t = 1; t <= T; t++) { scanf("%d", &num); printf("Case #%d:\n%I64d\n", t, Catalan[num]); } return 0; }
HDU4828 Grids 2014百度之星初赛题解,布布扣,bubuko.com
标签:style class blog code ext color
原文地址:http://blog.csdn.net/kenden23/article/details/32724971