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 ...
随机推荐
- java环境搭建的问题
本人用eclipse开发,首先在java官网中下载最新版本的jdk,jdk的版本一定要与eclipse版本位数相同,否则会提示错误“Java was started but returned exit ...
- LeetCode 解题报告--202Happy Number
1 题目描述 Write an algorithm to determine if a number is "happy". A happy number is a number ...
- ubuntu 安装dell无线网卡2
以下转自:http://blog.sina.com.cn/s/blog_73b6331101016haq.html ubuntu 12.04 bcm43xx无线网卡安装记录 (2012-07-01 0 ...
- Django开发网站(二)
第一课:视图显示 1 建立一个项目:django-admin startproject blog, 进入blog: cd blog 显示:blog(__init__.py settings.py ...
- 在MVVMLight框架的ViewModel中实现NavigationService
网上已经有很多方法了,比如通过Messenger来实现等等.这里我只讲述一种我比较喜欢的方法,因为它很方便 首先定义一个ViewModel基类,将所有ViewModel子类继承这个基类.在基类中定义 ...
- 【linQ】DataContext 入门 , 和 hql , jpql 一样好用
DataContext 和 LINQ结合后会有巨大的能量 public class UserDataContext : DataContext { public Table<User> U ...
- 【MongoDB】 安装为windows services
参考 http://stackoverflow.com/questions/2404742/how-to-install-mongodb-on-windows # mongodb.conf # da ...
- mac使用wget下载网站(仿站)
wget -c -r -np -k -L -p http://www.xxxx.com 参考 wget的安装 http://blog.csdn.net/ssihc0/article/details/7 ...
- [译] ASP.NET 生命周期 – ASP.NET 上下文对象(八)
使用 HttpResponse 对象 HttpResponse 对象是与 HttpRequest 对象相对应的,用来表示构建中的响应.它当中提供了方法和属性可供我们自定义响应,有一些在使用 MVC 视 ...
- HTML 菜单 a 标签设置样式
html: "<div style='font-weight:800;color:red'> <a href='javascript:void(0)'style='colo ...