POJ - 1942 D - Paths on a Grid
Fortunately you have a piece of squared paper and you choose a rectangle of size n*m on the paper. Let's call this rectangle together with the lines it contains a grid. Starting at the lower left corner of the grid, you move your pencil to the upper right corner, taking care that it stays on the lines and moves only to the right or up. The result is shown on the left: 
Really a masterpiece, isn't it? Repeating the procedure one more time, you arrive with the picture shown on the right. Now you wonder: how many different works of art can you produce?
Input
Output
Sample Input
5 4
1 1
0 0
Sample Output
126
2 题意:输入n,m,代表n*m的矩阵,求从左下角到右上角的方法有多少种
思路:用我们平常的加法原理可以得出这个答案,但是n,m范围是unsigned int我们不能开这么大的数组
我们可以发现其实我们肯定会走n+m步,其中n步向上,m步向右,我们走上,我们路线肯定是由
n个上,m个右组成,所以我们在这求出一个组合数C(n+m,m),代表从这个路线顺序里面挑出
m个位置为向右走,用C(n+m,n)也是一样的结果
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
unsigned C(unsigned n,unsigned m)//n,m的每个地方都记得用unsigned类型
{
if(m>n-m) m=n-m;
unsigned t1,t2;
t1=n;
t2=m;
double vis=1.0;
while(t2>)//用double型存储组合数,可以每次进行约分,如果是实在是整型不好存储的话那就只能使用这个进行约分了
{
vis*=(double)(t1--)/(double)(t2--);
}
return (unsigned)(vis+0.5);//四舍五入
}
unsigned n,m;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
if(!m && !n)
break;
cout<<C(n+m,n)<<endl;
}
}
POJ - 1942 D - Paths on a Grid的更多相关文章
- POJ 1942:Paths on a Grid
		
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22918 Accepted: 5651 ...
 - [ACM] POJ 1942 Paths on a Grid (组合)
		
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21297 Accepted: 5212 ...
 - tarjan算法求桥双连通分量  POJ 3177 Redundant Paths
		
POJ 3177 Redundant Paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12598 Accept ...
 - 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 3177 Redundant Paths POJ 3352 Road Construction(双连接)
		
POJ 3177 Redundant Paths POJ 3352 Road Construction 题目链接 题意:两题一样的.一份代码能交.给定一个连通无向图,问加几条边能使得图变成一个双连通图 ...
 - 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)$ 但 ...
 - POJ 1942 Paths on a Grid(组合数)
		
http://poj.org/problem?id=1942 题意 :在一个n*m的矩形上有n*m个网格,从左下角的网格划到右上角的网格,沿着边画,只能向上或向右走,问有多少条不重复的路 . 思路 : ...
 
随机推荐
- 【洛谷p2822】组合数问题
			
(突然想 ??忘掉了wdt) (行吧那就%%%hmr) 组合数问题[传送门] (因为清明要出去培训数学知识所以一直在做数论) 组合数<=>杨辉三角形(从wz那拐来的技能 ...
 - python记录_day14 内置函数二 迭代 二分法
			
一.匿名函数 形式: lambda 形参:返回值 lambda表示的是匿名函数. 不需要用def来声明, 一句话就可以声明出一个函数.匿名函数不是说一定没名字,而是他们的名字统一称为“lambda”, ...
 - CCF-CSP 201312-5  I'm stuck !
			
I'm stuck 试题编号: 201312-5 试题名称: I’m stuck! 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 给定一个R行C列的地图,地图的每一个方格可能 ...
 - nyoj-1250-exgcd
			
机器人 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Dr. Kong 设计的机器人卡尔非常活泼,既能原地蹦,又能跳远.由于受软硬件设计所限,机器人卡尔只能定点跳远 ...
 - SEND EMAIL SO_DOCUMENT_SEND_API1
			
FUNCTION zcrm_send_email_and_attach . *"------------------------------------------------------- ...
 - spring cloud服务发现注解之@EnableDiscoveryClient与@EnableEurekaClient
			
使用服务发现的时候提到了两种注解,一种为@EnableDiscoveryClient,一种为@EnableEurekaClient,用法上基本一致,今天就来讲下两者,下文是从stackoverflow ...
 - Linux Shell获取系统资源使用百分比(CentOS)
			
CPU使用率: top -b -n | | 内存使用率: free -m | grep '^-' | awk '{print $3/($3+$4)*100"%"}' IO使用率(F ...
 - Linux/AIX/Windows端口和进程互查
			
经常我们需要通过端口号查是哪个进程占用,或想查看某个进程占用了哪些端口. 1.1Linux上通过端口查找进程 比如我们想知道当前系统中80端口是哪个进程所占用 netstat -anp| |more ...
 - CentOS下安装Hbase
			
1.安装JDK.https://www.cnblogs.com/zhi-leaf/p/10315125.html 2.下载Hbase.下载地址:https://hbase.apache.org/dow ...
 - python2x 与 python3x 区别
			
python2.x 与 python3.x 的区别: 1. python2.x 的源码编码不规范,源码重复较多:python3.x 的源码编码规范,清晰.优美.简单 2. python2.x的默认字符 ...
 
			
		