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 ...
随机推荐
- linux umount 提示device is busy 的解决
linux umount 提示"device is busy" 终极解决 为了干净地关闭或热交换 UNIX 或类 UNIX 系统上的存储硬件,必须能够卸载使用此设备上的存储的所有文件系统.但是,如果正 ...
- 第五十八篇、iOS 微信聊天发送小视频的秘密
对于播放视频,大家应该一开始就想到比较方便快捷使用简单的MPMoviePlayerController类,确实用这个苹果官方为我们包装好了的 API 确实有很多事情都不用我们烦心,我们可以很快的做出一 ...
- Cocos2d-x中使用音频CocosDenshion引擎介绍与音频文件的预处理
Cocos2d-x提供了一个音频CocosDenshion引擎,CocosDenshion引擎可以独立于Cocos2d-x单独使用,CocosDenshion引擎本质上封装了OpenAL音频处理库.具 ...
- using System.Reflection;
基础代码: public interface IDBHelper { void Query(); } public class DBHelper : IDBHelper { public int Id ...
- Easyui 加载树(easyui-tree)[dotnet]
前台 html: <ul class="easyui-tree" id="ul_Tree" data-options="fit:true,ani ...
- axure注册码
ahjesus Axure RP 7.0注册码 用户名:axureuser 序列号:8wFfIX7a8hHq6yAy6T8zCz5R0NBKeVxo9IKu+kgKh79FL6IyPD6lK7G6+t ...
- rolling hash
也是需要查看,然后修改,rolling hash, recursive hash, polynomial hash, double hash.如果一次不够,那就2次.需要在准备一个线段树,基本的线段树 ...
- Contest1065 - 第四届“图灵杯”NEUQ-ACM程序设计竞赛(个人赛)A蔡老板的会议
题目描述 图灵杯个人赛就要开始了,蔡老板召集俱乐部各部门的部长开会.综合楼有N (1<=N<=1000)间办公室,编号1~N每个办公室有一个部长在工(mo)作(yu),其中X号是蔡老板的办 ...
- JQuery的过滤选择器
1.eg(num):查找索引num位置的元素,索引从0开始. 2.lt(num):查找索引小于num位置的元素,索引从0开始. 3.gt(num):查找索引大于num位置的元素,索引从0开始. 示例: ...
- 使用分部类给Models添加验证Attributes
网摘1: 在使用Entity Framework 的Database frist或model first时,直接加attribute到modle类上是太现实也不合理的,因为model类是自动生成的,重 ...