POJ-1942 Paths on a Grid 组合数

  题目链接:http://poj.org/problem?id=1942

  水题一枚,递推求解组合数即可。

 1 //STATUS:C++_AC_16MS_184KB
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5 #include<math.h>
 6 #include<iostream>
 7 #include<string>
 8 #include<algorithm>
 9 #include<vector>
10 #include<queue>
11 #include<stack>
12 using namespace std;
13 #define LL __int64
14 #define pii pair<int,int>
15 #define Max(a,b) ((a)>(b)?(a):(b))
16 #define Min(a,b) ((a)<(b)?(a):(b))
17 #define mem(a,b) memset(a,b,sizeof(a))
18 #define lson l,mid,rt<<1
19 #define rson mid+1,r,rt<<1|1
20 const int N=310,INF=0x3f3f3f3f,MOD=1999997;
21 const LL LLNF=0x3f3f3f3f3f3f3f3fLL;
22 
23 LL n,m;
24 
25 LL C(LL n,LL m)
26 {
27     m=Min(m,n-m);
28     LL s=1,i;
29     for(i=0;i<m;i++)s=s*(n-i)/(i+1);
30     return s;
31 }
32 
33 int main()
34 {
35   //  freopen("in.txt","r",stdin);
36     while(~scanf("%I64d%I64d",&n,&m) && (n||m))
37     {
38         printf("%I64d\n",C(n+m,n));
39     }
40     return 0;
41 }

 

posted @ 2013-01-20 01:58  zhsl  阅读(158)  评论(0编辑  收藏  举报