首页 > 代码库 > nyoj(简单数学)Oh, my Paper!

nyoj(简单数学)Oh, my Paper!

Oh, my Paper!

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述
Give you a piece of paper, n (row) *m (column) to calculate your is
Calculated from a diagonal line to another diagonal how many walk method (only upward or downward, left, and right away).
输入
The input contains several testcases. Each is specified by two unsigned 32-bit integers n and m The last test case is followed by a line that contains two zeroes. This line must not be processe
输出
For each test case output on a line that how many paths you can calculate
样例输入
2 3
1 1
0 0
样例输出
10
2
提示
the num is a little big ,you‘d better use unsigned
来源
原创
上传者

ACM_贺荣伟

思路:(直接用伟哥的)给你一张纸,n(行)*m(列)你要计算的是
算出从一个对角线到另一个对角线有多少走法(只能向上,向右走)。
分析:一个矩阵,它有行有列,要到达对角线,必定有通过所有的行和列,那么存在两种情况,当行(n)==列(m),即刚好走完列和行,在m+n个里选m或n个组合得C(m+n,m)或C(m+n,n)。
当两者不相等,就要看那个先到,所有最小的必定先到达。

#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main()
{
    long long n,m;
    while(~scanf("%lld%lld",&n,&m),n||m)
    {
        long long a,b;
        a=n+m;
        b=n<m?n:m;
        double sum=1;
        while(b>0)
            sum*=(a--/(double)(b--));
        printf("%.lf\n",sum);
    }
}


nyoj(简单数学)Oh, my Paper!