小兔的棋盘 2067

Problem Description
小兔的叔叔从外面旅游回来给她带来了一个礼物,小兔高兴地跑回自己的房间,拆开一看是一个棋盘,小兔有所失望。不过没过几天发现了棋盘的好玩之处。从起点(0,0)走到终点(n,n)的最短路径数是C(2n,n),现在小兔又想如果不穿越对角线(但可接触对角线上的格点),这样的路径数有多少?小兔想了很长时间都没想出来,现在想请你帮助小兔解决这个问题,对于你来说应该不难吧!
 

 

Input
每次输入一个数n(1<=n<=35),当n等于-1时结束输入。
 

 

Output
对于每个输入数据输出路径数,具体格式看Sample。
 

 

Sample Input
1 3 12 -1
 

 

Sample Output
1 1 2 2 3 10 3 12 416024
 

 

Author
Rabbit
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  2064 2065 1133 2068 1267 
 
 
 
 
 
 1 #include<stdio.h>
 2  __int64 a[38]={1,1};
 3 int catalan(int i,int j)
 4 {
 5    for(;i<38;i++)
 6     {a[i]=0;
 7         for(;j<=i;j++)
 8           a[i]+=a[j]*a[i-j-1];
 9           j=0;
10     }
11 }
12 int main()
13 {
14     int i=1,j=0;
15     catalan(i,j);
16     int t=1,n;
17     while(~scanf("%d",&n)&&(n!=-1))
18     {
19         printf("%d %d %I64d\n",t,n,2*a[n]);
20         t++;
21     }
22     return 0;
23 }

 

 

 

卡特兰数。。需要注意要用h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (n>=2)这个公式否则会溢出。

数论
posted @ 2015-07-06 13:30  Vmetrio  阅读(235)  评论(0编辑  收藏  举报