hdu 2067 小兔的棋盘

http://acm.hdu.edu.cn/showproblem.php?pid=2067

这是一道卡特兰数,请看资料:http://baike.baidu.com/view/2499752.htm其实就是应用

代码:

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <math.h>

int main()

{

    int m,i,j,t=0;

    __int64 a[40][40];

    while(scanf("%d",&m),m!=-1)

    {

          t++;

          memset(a,0,sizeof(a));

          a[1][1]=1;

          for(int i=2;i<=m+1;++i)

          for(int j=1;j<=i;++j)

          {

                if(j==1)

                a[i][j]=a[i-1][j];

                else if(j==i)

                a[i][j]=a[i][j-1];

                else

                a[i][j]=a[i-1][j]+a[i][j-1];  

          }

          printf("%d %d %I64d\n",t,m,a[m+1][m+1]*2);

    } 

    return 0;

}

posted @ 2011-08-12 19:55  ○o尐懶錨o  阅读(400)  评论(0编辑  收藏  举报