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 ...
随机推荐
- jQuery学习一:jQuery中的ready和load事件
//ready事件 $(document).ready(function(){ 代码........ }); //ready事件简写: $(function(){ 代码........ }); //l ...
- css3学习笔记之2D转换
translate() 方法 translate()方法,根据左(X轴)和顶部(Y轴)位置给定的参数,从当前元素位置移动. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
- Ueditor设置默认字体
其实很简单,只需要将ueditor.all.js 以及 ueditor.all.min.js 两个文件中的字体改掉即可 修改方法: 在ueditor.all.js中搜索:设置默认字体和字号: 在ued ...
- DTCMS会员中心快速更改样式思路
非常简便 制作一个public.css文件,包含网站头部和底部的样式代码 每个会员中心模版导入这个文件就可以 把原先style.css的头部和底部样式代码删除
- C# Json数据反序列化为Dictionary并根据关键字获取指定值
Json数据: { "dataSet": { "header": { "returnCode": "0", " ...
- [DevExpress]设置RepositoryItemComboBox只可下拉选择不可编辑
将TextEditStyle属性设置如下即可: 希望有所帮助!
- Responsive设计——不同设备的分辨率写法
1.1024px显屏 @media screen and (max-width : 1024px) { /* 样式写在这里 */ } 2.800px显屏 @media screen and (max- ...
- 用 .htaccess 实现网址规范化
网址规范化在 SEO 中是一个比较重要的环节,同时存在不同的网址版本,不但可能造成内容重复,还不能正确的集中权重.目前大多数网站,绑定的域名都有带 www 和不带两个版本,甚至很多网站同时绑定多个域名 ...
- JS远程获取网页源代码的例子
js代码获取网页源代码. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> < ...
- 运用百度开放平台接口根据ip地址获取位置
使用百度开放平台接口根据ip地址获取位置 今天无意间发现在百度开放平台接口,就把一段代码拿了下来,有需要的可以试试看:http://opendata.baidu.com/api.php?query=5 ...