poj 1942 Paths on a Grid

简单的组合题:

View Code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#include<vector>
#include<string>
#define LL long long
using namespace std;
LL Gcd( LL a, LL b )
{
   return b ==0 ? a : Gcd( b , a % b );    
}
LL Get_C( LL n ,LL m )
{
   LL ans = 1,ans1 = 1;
   while( m )
   {
      ans *= n;
      ans1 *=m;
      LL t = Gcd( ans ,  ans1 );
      ans /= t;
      ans1 /= t;
      n --;
      m --;
   }    
   return ans/ans1;
}
int main(  )
{
    LL n,m;
    while( scanf( "%I64d %I64d",&n,&m ),n|m )
    {
          printf( "%I64d\n",Get_C( n+m ,min( n , m ) ) );    
    }
    //system( "pause" );
    return 0;
}

 

posted @ 2012-08-13 10:40  wutaoKeen  阅读(127)  评论(0)    收藏  举报