POJ-1942 Paths on a Grid 组合数

注意输出结果也是在32位无符号内就可以了。

代码如下:

#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long Int64;

Int64 C(Int64 a, Int64 b) {
    Int64 ret = 1;
    for (int i = 0; i < a; ++i) {
        ret *= (b-i);
        ret /= (i+1);
    }
    return ret;
}

int main() {
    Int64 a, b, m;
    while (scanf("%I64d %I64d", &a, &b), a | b) {
        m = min(a, b);
        printf("%I64d\n", C(m, a+b));
    }
    return 0;
}

 

posted @ 2012-09-12 07:40  沐阳  阅读(183)  评论(0编辑  收藏  举报