Contest2037 - CSU Monthly 2013 Oct (problem B 1320 :Scoop water 卡特兰数)
你为何这么叼!
1320: Scoop water
Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 327 Solved: 78
[Submit][Status][Web Board]
Description
zzy今天刚买了两个水瓢A和B,容量都是为1升,童心未泯的他打算用这个水瓢来玩游戏。
首先zzy准备了一个容量可看作无穷大的水缸,刚开始水缸是空的,然后用水瓢A往水缸里加水,用水瓢B把水缸里的水舀出去,当使用 水瓢B把水舀出去时水缸里必须要至少有1升的水。这样子使用N次水瓢A,也使用N次水瓢B,最后水缸会依旧空的。
Input
输入有多个例子,直到文件结束。
每个例子仅含一个数N(0<N<=10000),表示你必须使用N次A水瓢和N次B水瓢。
Output
对于每个例子,请输出一个数,表示一共有多少种正确的舀水方式使得舀水过程中 使用B水瓢时水缸里总会有足够的水。
(由于数字比较大,输出的答案模1000000007)
Sample Input
1
2
Sample Output
1
2
HINT
CSU_CX
Source
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 #define ll long long 6 #define maxn 10005 7 #define mod 1000000007 8 int n,m; 9 ll a[maxn]; 10 int ex_gcd(int a,int b,int &x,int &y){ 11 int res; 12 if(!b){x=1;y=0;return a;} 13 res=ex_gcd(b,a%b,y,x); 14 y-=x*(a/b); 15 return res; 16 } 17 void init(){ 18 a[1]=1; 19 for(int i=2;i<maxn;i++){ 20 a[i]=a[i-1]*(4*i-2)%mod; 21 int x,y; 22 ex_gcd(i+1,mod,x,y); 23 a[i]=(a[i]*((x+mod)%mod)+mod)%mod; 24 } 25 } 26 int main(){ 27 init(); 28 while(~scanf("%d",&n)) 29 printf("%lld\n",a[n]); 30 return 0; 31 }
浙公网安备 33010602011771号