POJ 1942 Paths on a Grid(组合数)
http://poj.org/problem?id=1942
题意 :在一个n*m的矩形上有n*m个网格,从左下角的网格划到右上角的网格,沿着边画,只能向上或向右走,问有多少条不重复的路 。
思路 :这种问题记得高中的时候就做过,学组合数的时候讲的,反正就是向上向右走,加起来要走的路必定为n+m条,选择n条向上,必定剩下的m为向右的,所以这个题就转化求C(n,m+n),或者是C(m,m+n),不过个人建议用m,n中小的那个数去做,因为省时。因为这个数据较大,所以求组合的时候就要注意以防超时,如果还像1850那样用杨辉三角就容易超时了,就要用另一种方法去求组合数,我以前整理过4种求组合数的方法,正好第四种这里可以用,拆分相除,逐项相乘。
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip> using namespace std ; double com(unsigned n,unsigned m)
{
unsigned a = m+n ;
unsigned b = min(m,n) ;
double comm = 1.0 ;
while(b > )
comm *= (double)(a--)/(double)(b--) ;
return comm ;
} int main()
{
unsigned m,n ;
while(scanf("%d %d",&m,&n)&&(m||n))
{
cout<<fixed<<setprecision()<<com(n,m)<<endl ;
}
return ;
}
POJ 1942 Paths on a Grid(组合数)的更多相关文章
- [ACM] POJ 1942 Paths on a Grid (组合)
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21297 Accepted: 5212 ...
- POJ 1942 Paths on a Grid
// n*m 的格子 从左下角走到右上角的种数// 相当于从 n+m 的步数中选 m 步往上走// C(n+m,m) #include <iostream> #include <st ...
- poj 1924 Paths on a Grid(组合数学)
题目:http://poj.org/problem?id=1942 题意:给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有 ...
- POJ 1942:Paths on a Grid
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22918 Accepted: 5651 ...
- poj1942 Paths on a Grid(无mod大组合数)
poj1942 Paths on a Grid 题意:给定一个长m高n$(n,m \in unsigned 32-bit)$的矩形,问有几种走法.$n=m=0$时终止. 显然的$C(m+n,n)$ 但 ...
- Paths on a Grid(简单组合数学)
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23008 Accepted: 5683 Desc ...
- POJ1942——Paths on a Grid(组合数学)
Paths on a Grid DescriptionImagine you are attending your math lesson at school. Once again, you are ...
- Paths on a Grid(规律)
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23270 Accepted: 5735 ...
- poj——3177Redundant Paths
poj——3177Redundant Paths 洛谷—— P2860 [USACO06JAN]冗余路径Redundant Paths Time Limit: 1000MS Memory ...
随机推荐
- poi-3.11-beta2-20140822.jar操作excel方法
poi-3.11-beta2-20140822.jar操作excel方法 根据不同类型读取值的方法: // 获取单元格内不同类型的值 public String getValueByType(HSSF ...
- c# 远程回收IIS应用池
利用下列代码可实现IIS应用池的远程回收 var serverManager = ServerManager.OpenRemote(ip); var appPools = serverManager. ...
- PHP标签的格式
PHP标签的格式: 1.xml格式(推荐的,标准的标记) <?php php代码?> 示例: 2.短格式 <? php代码 ?> 此种格式需要在php.ini中配置 示例 ...
- Js 对象三
一.screen对象 Width:屏幕的宽度 Height:屏幕的高度 availWidth:屏幕的有效宽度 availhHeight:屏幕的有效高度 (不包含任务栏) colorDepth:色深 二 ...
- template_1
0: 模板是一些为多种类型而编写的函数和类,而且这些类型都没有指定.当使用模板的时候,只需要把所希望的类型作为一个(显示或隐示的)实参传递给模板.模板是语言本身所具有的特效,她完全支持类型检查和作用域 ...
- VS2010远程调试
1, A:调试机. B:远端被调试机. 2, 从A机的VS2010的安装目录里面,找到../Remote Debugger文件,复制到B机. 3, 启动B机上复制过来的目录下的msvsmon.exe ...
- Using OpenCV Java with Eclipse
转自:http://docs.opencv.org/trunk/doc/tutorials/introduction/java_eclipse/java_eclipse.html Using Open ...
- jobs
fg.bg.jobs.&.ctrl + z都是跟系统任务有关的,虽然现在基本上不怎么需要用到这些命令,但学会了也是很实用的一.& 最经常被用到这个用在一个命令的最后,可以把这个命令放到 ...
- [DevExpress]ChartControl之SeriesTemplate示例
关键代码: using System; using System.Data; using System.Windows.Forms; using CSharpUtilHelpV2; using Dev ...
- Spark小课堂Week7 从Spark中一个例子看面向对象设计
Spark小课堂Week7 从Spark中一个例子看面向对象设计 今天我们讨论了个问题,来设计一个Spark中的常用功能. 功能描述:数据源是一切处理的源头,这次要实现下加载数据源的方法load() ...