poj 1924 Paths on a Grid(组合数学)
题目:http://poj.org/problem?id=1942
题意:给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有多少种走法,每步只能向上或者向右走
题解:就是 上和 右的排列。
用c(m,n)=n!/m!*(n-m)!;
最重要的是算阶乘。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; unsigned comb(unsigned m,unsigned n)
{
unsigned a,b;
double cnt=1.0;
a=m+n;
b=(m>n?n:m);//从m n中选一个较小的
while(b)
cnt*=double(a--)/double(b--);//一种求c(b,a)的比较快的方法。
cnt+=0.5;//最后结果要四舍五入,所以要加0.5
return (unsigned)cnt;
}
int main()
{
unsigned n,m;//必须用unsigned,如果用int 会wa.
while(cin>>m>>n&&(n||m))
cout<<comb(m,n)<<endl;
return ;
}
poj 1924 Paths on a Grid(组合数学)的更多相关文章
- POJ1942——Paths on a Grid(组合数学)
Paths on a Grid DescriptionImagine you are attending your math lesson at school. Once again, you are ...
- [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(组合数)
http://poj.org/problem?id=1942 题意 :在一个n*m的矩形上有n*m个网格,从左下角的网格划到右上角的网格,沿着边画,只能向上或向右走,问有多少条不重复的路 . 思路 : ...
- POJ 1942 Paths on a Grid
// n*m 的格子 从左下角走到右上角的种数// 相当于从 n+m 的步数中选 m 步往上走// C(n+m,m) #include <iostream> #include <st ...
- 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 ...
- Paths on a Grid(规律)
Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23270 Accepted: 5735 ...
- 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——3177Redundant Paths
poj——3177Redundant Paths 洛谷—— P2860 [USACO06JAN]冗余路径Redundant Paths Time Limit: 1000MS Memory ...
随机推荐
- 一款jquery写出来的tab切换
当时做这个的时候,当前状态是不规则的,li对应的有3块内容,分别设定不同背景图片,只显示当前的一个背景,鼠标移上去的时候其余2个用background-position: -1000px 0px;来隐 ...
- js自运行函数
学习闭包的基础知识: 函数声明 function fn(){ //这里是代码 }; fn(); //运行fn函数 与上面等价 var fn = function(){ //这里是代码 } fn(); ...
- PHP中刷新输出缓冲,立即输出数据
<script type="text/javascript"> function show_message(message) { document.getElement ...
- IOS苹果购买PHP服务器端验证(订阅购买和一次性购买通用)
// 正式环境验证地址 $ios_verify_url = 'https://buy.itunes.apple.com/verifyReceipt'; // 测试环境验证地址 $ios_sandbox ...
- [Interview][CodingExam]
這次去Interview, 其中有一個公司 把我列為 2/25的考慮對象, 在Final 的 1/2, 我被刷掉了. 因為第一輪的程式,我稍微google了一下,參考了既有的寫法. 即使第二輪我用完全 ...
- Linux 服务器如何禁止 ping 以及开启 ping
Linux 默认是允许 ping 响应的,也就是说 ping 是开启的,但 ping 有可能是网络攻击的开始之处,所以关闭 ping 可以提高服务器的安全系数.系统是否允许 ping 由2个因素决定的 ...
- 长安CS15_手动——16款
一.输入数据 1.CAN总线描述:位置,颜色,速率,总线类型 1)位置:OBD 2)颜色:3) 速率:500k 4)总线类型:HSCAN 5)测试时间:2016.5.4 2.车辆特征 1)排量:1.5 ...
- PHP webserver 之 soap 生成wsdl文件
<?php /** * Copyright (c) , Braulio Jos?Solano Rojas * All rights reserved. * * Redistribution an ...
- Oracle bug 使用max或min函数into到一个char类型报字符缓冲区太小的错误
这个BUG出现会报错如下: selectto_char(max(RENEWAL_DATE)) intoM_YEAR_MONTH fromt_renewal_schedule; ORA-06502: P ...
- C# 写XML文件
/// <summary>x /// 修改xml文件 /// </summary> /// <param name="dt"></para ...