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);
}
 #include<iostream>
#include<cstdio>
#include<cstring>
#define re register
using namespace std;
typedef unsigned us;
us min(us a,us b){return a<b?a:b;}
us n,m;
us C(us a,us b){
double cnt=1.0;
while(b) cnt*=(double)(a--)/(double)(b--);
return (us)(cnt+0.5);
}
int main(){
while(cin>>n>>m){
if(!n&&!m) return ;
cout<<C(n+m,min(n,m))<<endl;
}
}

poj1942 Paths on a Grid(无mod大组合数)的更多相关文章

  1. POJ1942——Paths on a Grid(组合数学)

    Paths on a Grid DescriptionImagine you are attending your math lesson at school. Once again, you are ...

  2. poj1942 Paths on a Grid

    处理阶乘有三种办法:(1)传统意义上的直接递归,n的规模最多到20+,太小了,在本题不适用,而且非常慢(2)稍快一点的算法,就是利用log()化乘为加,n的规模虽然扩展到1000+,但是由于要用三重循 ...

  3. POJ1942 Paths on a Grid(组合)

    题目链接. 分析: #include <cstdio> #include <iostream> #include <map> #include <cstrin ...

  4. [ACM] POJ 1942 Paths on a Grid (组合)

    Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21297   Accepted: 5212 ...

  5. Paths on a Grid(规律)

    Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 23270   Accepted: 5735 ...

  6. Paths on a Grid(简单组合数学)

    Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23008 Accepted: 5683 Desc ...

  7. POJ 1942:Paths on a Grid

    Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22918   Accepted: 5651 ...

  8. Lucas 大组合数

    题目:HDU 3037 题意:有n个树,m个坚果,放到n个树里,可以不放完,有多少种方法. 分析: 得到组合数了. 大组合数什么费马小定理,Lucas定理都来了: 总的说,不能用二维地推了,用的却是组 ...

  9. 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数

    typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1&l ...

随机推荐

  1. MQTT的学习研究(十六) MQTT的Mosquitto的window安装部署

    在mqtt的官方网站,有许多mqtt,其中:MosquittoAn Open Source MQTT server with C, C++, Python and Javascript clients ...

  2. 布局的诡异bug合集+解决方法(更新中)

    1.元素内部子元素的margin的边界线基准点的问题 论如何生硬起名字!!我反正已经被自己总结的题目绕晕了... “演员”介绍: 外层父元素:蓝色边框: 内部子元素:绿色区域: 粉红色区域是元素内部绿 ...

  3. 腾讯云CMQ消息队列在Windows环境下的使用

    版权声明:本文由李少华原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/100 来源:腾云阁 https://www.qclo ...

  4. 域渗透学习预备知识-IPC$的入侵防御

    一.什么是IPC$ 以下段落引文自:http://www.xfocus.net/articles/200303/493.html IPC$(Internet Process Connection)是共 ...

  5. chrom调试

    2.Event Listeners 可以看到事件找到对应在标签点开里有useCapture, passive: once: handler等等右键handler 的"show functio ...

  6. 使用Spring报错:No default constructor found;

    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error ...

  7. 170620、springboot编程之页面版Hello World

    书接上回,把Hello World 在页面上显示! 1.在pom文件中加入web支持 <dependency> <groupId>org.springframework.boo ...

  8. 2017ACM-ICPC沈阳区域赛

    I-Little Boxes[大数] hdu6225  http://acm.hdu.edu.cn/showproblem.php?pid=6225 题意: 就是给四个大数,输出和. 思路: java ...

  9. 实现VMware下CentOS和Windows之间的复制粘贴

    实现VMware下CentOS和Windows之间的复制粘贴1.第一步,打开虚拟机2.点击菜单栏中的虚拟机->安装VMware Tools3.桌面中找到VMwareTools-10.0.10-4 ...

  10. SQL Server 复制(Replication) ——事务复制搭建

    本文演示如何搭建最基本的事务复制. 环境准备: 虚拟机2台: 服务器名分别为RepA和RepB,RepA为发布服务器,RepB为订阅服务器.均安装WindowsServer 2008R2英文版(在外企 ...