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. Visual Studio的MethMVVM

    MethMVVM介绍: Visual Studio Gallery是微软针对VisualStudio扩展提供的一种解决方案,在Visual Studio Gallery你能够找到各种不同主题的解决方案 ...

  2. sql2000下如何新建并使用dbml

    默认新建的dbml只是支持sql2005及其以上版本. 但是现在是sql2000怎么办?我要是想要用linq to sql 的? 解决方案如下: 1首先打开cmd,在其中cd到sqlmetal.exe ...

  3. DTCMS规格统一赋值

    admin\article_edit.aspx 已经存在 市场价格 和销售价格统一赋值 //赋值规格市场价格 $("#field_control_market_price").bl ...

  4. CURL的使用<发送与接收数据>

    $headers = array( "TYPE:xxxxooooo", "TOKEN:00000000" ); $data = array( 'data' =& ...

  5. (转载)sql语句解决分页问题

    <来源网址:http://www.delphifans.com/infoview/Article_353.html>sql语句解决分页问题日期:2005年1月17日 作者:treemon2 ...

  6. 百度地图api的实现

    获取客户端IP地址经纬度所在城市 <?php $getIp=$_SERVER["REMOTE_ADDR"]; echo 'IP:',$getIp; echo ''; $con ...

  7. 在后台对GameObject进行"创建"||"删除"动作

    在后台对GameObject进行"创建"||"删除"动作 建立 public GameObject Pre;//在编辑器中用来绑定的Prefabs public ...

  8. 2014年辛星完全解读Javascript第七节 数组和对象

    由于Javascript是脚本语言,因此,使用起来非常方便,数组的使用也是比较简单的,下面我们就主要介绍一下Javascript中数组的介绍,以及上一节中没有完成的对象的介绍. *********** ...

  9. Teradata基础教程中的数据库试验环境脚本

    Teradata基础教程中的数据库表: Customer:  客户信息表 Location:  位置信息表 Employee:  雇员信息表 Job:  工作信息表 Department:  部门表 ...

  10. JSON操作,转载

    http://www.cnblogs.com/mcgrady/archive/2013/06/08/3127781.html#_label0