poj1942 Paths on a Grid(无mod大组合数)
题意:给定一个长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大组合数)的更多相关文章
- POJ1942——Paths on a Grid(组合数学)
Paths on a Grid DescriptionImagine you are attending your math lesson at school. Once again, you are ...
- poj1942 Paths on a Grid
处理阶乘有三种办法:(1)传统意义上的直接递归,n的规模最多到20+,太小了,在本题不适用,而且非常慢(2)稍快一点的算法,就是利用log()化乘为加,n的规模虽然扩展到1000+,但是由于要用三重循 ...
- POJ1942 Paths on a Grid(组合)
题目链接. 分析: #include <cstdio> #include <iostream> #include <map> #include <cstrin ...
- [ACM] POJ 1942 Paths on a Grid (组合)
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21297 Accepted: 5212 ...
- Paths on a Grid(规律)
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23270 Accepted: 5735 ...
- Paths on a Grid(简单组合数学)
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23008 Accepted: 5683 Desc ...
- POJ 1942:Paths on a Grid
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22918 Accepted: 5651 ...
- Lucas 大组合数
题目:HDU 3037 题意:有n个树,m个坚果,放到n个树里,可以不放完,有多少种方法. 分析: 得到组合数了. 大组合数什么费马小定理,Lucas定理都来了: 总的说,不能用二维地推了,用的却是组 ...
- 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数
typedef long long ll; /********************************** 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1&l ...
随机推荐
- PyQt4滑块QSlider、标签QLabel
滑块部件由一个简单的操控杆构成,用户可以通过向前或向后滑动滑块来选择数据.这种选择数据的方式对一些特殊的任务来说比单纯的提供一个数据或使用spin box调整数据大小的方式要自然友好的多.而标签部件则 ...
- 程序启动-Runloop
0 从程序启动开始到view显示: start->(加载framework,动态静态链接库,启动图片,Info.plist,pch等)->main函数->UIApplicationM ...
- .Net内存溢出 System.OutOfMemoryException
内存溢出常见的情况和处理方式: http://outofmemory.cn/c/dotNet-outOfMemoryException MSDN中关于processModel的文档 https://m ...
- poj_1743 后缀数组
题目大意 给定一串数字,长度为N.定义数字中的某个连续的子串为一个"theme",只要子串满足: (1)长度 >= 5 (2)和该子串相同或者该子串的“变种串”在整串数字中出 ...
- CSS写表格
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content_Type" content ...
- LeetCode——Power of Two
Description: Given an integer, write a function to determine if it is a power of two. public class S ...
- [Java语言] HashMap,HashSet,Hashtable,Vector,ArrayList 的关系 <转>
这么几个比较常用的但是比较容易混淆的概念同出于 java.util 包.本文仅作几个类的浅度解析. (本文基于JDK1.7,源码来自openjdk1.7.) ├── Collection │ ├── ...
- Java初学者笔记一:元类、获取类型、枚举
零.绪论: 2018年新年伊始,学习Java的冲动越来越强烈,毕竟以后无论是做安全开发还是安全研究都必不可少的掌握这门语言,所以在不断完善Python作为脚本语言的主语言的情况下觉得学习Java作为高 ...
- python的三个函数(eval、exec、complie)和python版RMI
一.python的三个函数: 1.eval函数: 之前已经讲过了这个函数,该函数也类似于php的eval,例如下边这个例子 eval("os.system('id')") 但是有个 ...
- Python - 3.6 学习四
错误.调试和测试 程序运行中,可能会遇到BUG.用户输入异常数据以及其它环境的异常,这些都需要程序猿进行处理.Python提供了一套内置的异常处理机制,供程序猿使用,同时PDB提供了调试代码的功能,除 ...