Paths on a Grid(poj 1942)

给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有多少种走法,每步只能向上或者向右走。

//注意循环的时候,要循环小的数,否则会超时
#include<cstdio>
#include<iostream>
#define LL long long
using namespace std;
int main()
{
    while(1)
    {
        LL a,b,ans=1;
        cin>>a>>b;
        if(a==0&&b==0)break;
        LL m=a+b;
        b=min(a,b);
        for(LL i=1;i<=b;i++)
        {
            ans*=(m-(i-1));
            ans/=i;
        }
        cout<<ans<<endl;
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/harden/p/5643724.html