# hdu5673(默慈金数、卡特兰数)

Robot
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 337 Accepted Submission(s): 173

Problem Description
There is a robot on the origin point of an axis.Every second, the robot can move right one unit length or do nothing.If the robot is
on the right of origin point,it can also move left one unit length.A route is a series of movement. How many different routes there are
that after n seconds the robot is still located on the origin point?

Input
There are multiple test cases. The first line of input contains an integer T(1≤T≤100) indicating the number of test cases. For each test case:

The only line contains one integer n(1≤n≤1,000,000).

Output
For each test case, output one integer.

Sample Input

3
1
2
4

Sample Output

1
2
9

#include<cstdio>

typedef long long ll;
const ll mod=1000000007;
const int maxn=1000005;
ll catalan[maxn],inv[maxn],fact[maxn];

ll Pow(ll n,ll m){
ll sum=1,t=n;
//    printf("%lld %lld\n",n,m);
while(m){
if(m&1){
sum*=t;
if(sum>=mod)sum%=mod;
}
t*=t;
if(t>=mod)t%=mod;
m>>=1;
}
return sum;
}

ll C(ll n,ll m){
if(m>n||m<0)return 0;
return fact[n]*inv[m]%mod*inv[n-m]%mod;
}

int main(){
//    printf("%lld %lld\n",Pow(2,3),Pow(2,0));return 0;
catalan[0]=1;
for(int i=1;i<maxn;++i){
catalan[i]=(catalan[i-1]*(4*i-2)%mod)*Pow(i+1,mod-2)%mod;
}
fact[0]=1;
for(int i=1;i<maxn;++i){
fact[i]=fact[i-1]*i%mod;
}
inv[0]=1;
for(int i=1;i<maxn;++i){
inv[i]=Pow(fact[i],mod-2)%mod;
}

int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
ll ans=0;
for(int i=0;i<=(n>>1);++i){
ans=ans+((catalan[i]*C((ll)n,(ll)i<<1))%mod);
ans%=mod;
}
printf("%lld\n",ans);
}
return 0;
}


11-18 4050

04-23 3060

04-26 435

09-29 56

01-13 1028

04-26 412

04-24 221

08-22 142

05-31 190

08-08 2587