现在的位置: 首页 > 综合 > 正文

poj 1942 Paths on a Grid

2018年01月12日 ⁄ 综合 ⁄ 共 772字 ⁄ 字号 评论关闭

#include<iostream>
#include<cstdio>
using namespace std;
/*
int com(int n,int r)//C(n,r)
{
if(n-r>r)r=n-r;
int i,j=1,ans=1;
for(i=0,j=1;i<r;i++)
{
ans*=(n-i);
for(;j<=r&&ans%j==0;j++)
ans/=j;
}
return ans;
}*/
long long com(long long n,long long r)
{
long long a=1,i;
for(i=1;i<=r;i++)
        a=a*(n-i+1)/i;//a*=(n-i+1)/i;
return a;
}

int main()
{
long long n,m;
while(scanf("%lld %lld",&n,&m)!=EOF)
{
long long temp=n;
if(n==0&&m==0)
break;
if(n>m)
temp=m;
long long   ans=com(n+m,temp);
printf("%lld\n",ans);

}
    system("pause");
return 0;
}

/*
#include <iostream>
using namespace std;
double CNM(unsigned int N, unsigned int M)
{
    M = (M > N - M) ? N - M : M;
    double ret = 1;
    while(M > 0)
ret *= double(N--) / double (M--);
    return ret;
}
int main(int argc, char* argv[])
{
    unsigned int A, B;
    while(scanf("%d %d", &A, &B) && !(A == 0 && B == 0))
        printf("%.0lf\n",CNM(A + B, B));
    return 0;
}*/

抱歉!评论已关闭.