码迷,mamicode.com
首页 > 其他好文 > 详细

poj1942 Paths on a Grid(无mod大组合数)

时间:2018-10-31 15:45:22      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:poj   1.0   sed   get   ace   onclick   while   href   tar   

poj1942 Paths on a Grid

题意:给定一个长m高n$(n,m \in unsigned 32-bit)$的矩形,问有几种走法。$n=m=0$时终止。

显然的$C(m+n,n)$

但是没有取模,n,m的范围又在unsigned int 范围内

于是有一种神奇的方法↓↓

typedef unsigned us;
us C(us a,us b){//C(a,b)
double cnt=1.0; while(b) cnt*=(double)(a--)/(double)(b--); return (us)(cnt+0.5); }
技术分享图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #define re register
 5 using namespace std;
 6 typedef unsigned us;
 7 us min(us a,us b){return a<b?a:b;}
 8 us n,m;
 9 us C(us a,us b){
10     double cnt=1.0;
11     while(b) cnt*=(double)(a--)/(double)(b--);
12     return (us)(cnt+0.5);
13 }
14 int main(){
15     while(cin>>n>>m){
16         if(!n&&!m) return 0;
17         cout<<C(n+m,min(n,m))<<endl;
18     }
19 }
View Code

 

poj1942 Paths on a Grid(无mod大组合数)

标签:poj   1.0   sed   get   ace   onclick   while   href   tar   

原文地址:https://www.cnblogs.com/kafuuchino/p/9882901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!