HDU 1267 下沙的沙子有几粒?

题解:利用卡特兰数的几何意义,题目就可以转化为一个棋盘格,可以向下走或是向右走,但是不可以逾越对角线,就可以了。

#include <cstdio>
#include <iostream>
using namespace std;
long long f[21][21];
int main()
{
    int m,n;
    for(int i=1; i<21; i++)
    f[i][1]=i;
    for(int m=1; m<=20; m++)
    for(int n=2; n<=20; n++)
    {
        f[m][n]=f[m-1][n]+f[m][n-1];
        if (m<n) f[m][n]=0;
    }
    while (cin>>m>>n) cout<<f[m][n]<<endl;
    return 0;
}

 

posted @ 2014-01-21 09:17  forever97  阅读(155)  评论(0编辑  收藏  举报