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(组合数)的更多相关文章

  1. [ACM] POJ 1942 Paths on a Grid (组合)

    Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21297   Accepted: 5212 ...

  2. POJ 1942 Paths on a Grid

    // n*m 的格子 从左下角走到右上角的种数// 相当于从 n+m 的步数中选 m 步往上走// C(n+m,m) #include <iostream> #include <st ...

  3. poj 1924 Paths on a Grid(组合数学)

    题目:http://poj.org/problem?id=1942 题意:给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有 ...

  4. POJ 1942:Paths on a Grid

    Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22918   Accepted: 5651 ...

  5. 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)$ 但 ...

  6. Paths on a Grid(简单组合数学)

    Paths on a Grid Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 23008 Accepted: 5683 Desc ...

  7. POJ1942——Paths on a Grid(组合数学)

    Paths on a Grid DescriptionImagine you are attending your math lesson at school. Once again, you are ...

  8. Paths on a Grid(规律)

    Paths on a Grid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 23270   Accepted: 5735 ...

  9. poj——3177Redundant Paths

    poj——3177Redundant Paths      洛谷—— P2860 [USACO06JAN]冗余路径Redundant Paths Time Limit: 1000MS   Memory ...

随机推荐

  1. AES加密解密的例子小结

    话不多说,先放上代码,一共有两个文件:AES.php(aes算法类文件)和aesDemo.php(应用实例文件),这里只贴出aesDemo.php,其他的看附件吧!aesDemo.php: 例子,   ...

  2. Android Timer用法

    Android考虑到线程安全问题,不允许在线程中执行UI线程,在Android中,有一个类:android.os.Handler,这个可以实现各处线程间的消息传递.先看段代码,这个实例化了一个Hand ...

  3. C# GET 和 SET作用

    C#中get和SET,看来看去还是看不懂,通俗一点解释一下,用了有什么好处,不用会怎么样 如果你这样写是没有什么不一样的. private int __Old; public int Old{ get ...

  4. String的几种初始化方法的区别

    参考了: java中String的两种初始化方法   String a; String aa = ""; String aaa = "123"; String ...

  5. 增加用户为SiteCollection的管理员

    1.SiteSettings-->Site collection administrators --> 增加你需要的用户

  6. 怎样在Android SDK 下查看应用程序输出日志的方法

          该文章源于安卓教程网(http://android.662p.com),转载时要注明文章的来自和地址,感谢你的支持. 在Android程序中可以使用 android.util.Log 类来 ...

  7. [CSS]三角形

    CSS盒子模型 当我们把padding和width,height全部设置为0,border设为一个较大的像素时 即:我们需要什么方向的三角形,只需把其余的三角形背景色设置为transparent:

  8. JavaScript jQuery 入门回顾 2

    JQuery 滑动 利用jQuery可以在元素上创建滑动效果. slideDown() 向下滑动元素. slideUp() 向上滑动元素. slideToggle() 在 slideDown() 与 ...

  9. 关于html5 -- plus Webview模块管理应用窗口界面

    Webview模块管理应用窗口界面,通过plus.webview可获取应用界面管理对象. 方法: all:获取所有的webview窗口 close:关闭webview窗口 create:创建新的web ...

  10. 使用Hibernate 拦截执行sql语句,并输出sql语句,获取sql语句

    重建包名 org.hibernate.type.descriptor.sql 重建类BasicBinder 代码如下 package org.hibernate.type.descriptor.sql ...