POJ1942-Paths on a Grid

题意:

给你两个数n,m,代表n*m的矩阵,让你求,从左下角走到右上角的方法数;

走法是只能往上走或者往右走。

这个题就是求组合数

从左下角走到右上角一共走n+m步,必须得走n步或者m步,所以从n+m中选择n步或者m步。

所以直接求Cnn+m  或者Cmn+m 都是答案

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <set>
 4 using namespace std;
 5 typedef long long ll; 
 6 int main()
 7 {
 8     ll n,m;
 9     while(~scanf("%lld%lld",&n,&m))
10     {
11         ll ans=1;
12         if(n==0&&m==0)
13             break;
14         ll t=m+n;
15         n=max(n,m);
16         for(ll i=n+1,j=1;i<=t;i++,j++)
17             ans=ans*i/j;
18         printf("%lld
",ans);
19     }
20 
21     return 0;
22 }
原文地址:https://www.cnblogs.com/Cherry93/p/9919826.html