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

Description

Imagine you are attending your math lesson at school. Once again, you are bored because your teacher tells things that you already mastered years ago (this time he's explaining that (a+b)2=a2+2ab+b2). So you decide to waste your time with drawing modern art instead.

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

The input contains several testcases. Each is specified by two unsigned 32-bit integers n and m, denoting the size of the rectangle. As you can observe, the number of lines of the corresponding grid is one more in each dimension. Input is terminated by n=m=0.

Output

For each test case output on a line the number of different art works that can be generated using the procedure described above. That is, how many paths are there on a grid where each step of the path consists of moving one unit to the right or one unit up? You may safely assume that this number fits into a 32-bit unsigned integer.

Sample Input

5 4
1 1
0 0

Sample Output

126
2
题解:找规律,总共走了m+n步,从这m+n步中选m步向右,规律很容易找出来,但是却是无符号的32位;
代码:
 #include<stdio.h>
#include<math.h>
const int MAXN=;
int main(){
__int64 N,ans;
int T;
scanf("%d",&T);
while(T--){
ans=;
scanf("%I64d",&N);
N++;
int flot=;
for(int i=;i<=sqrt(N);i++)if(N%i==)ans++;
printf("%I64d\n",ans);
}
return ;
}

Paths on a Grid(规律)的更多相关文章

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

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

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

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

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

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

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

  5. POJ 1942:Paths on a Grid

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

  6. POJ - 1942 D - Paths on a Grid

    Imagine you are attending your math lesson at school. Once again, you are bored because your teacher ...

  7. Paths on a Grid(poj 1942)

    给定一个矩形网格的长m和高n,其中m和n都是unsigned int32类型,一格代表一个单位,就是一步,求从左下角到右上角有多少种走法,每步只能向上或者向右走. //注意循环的时候,要循环小的数,否 ...

  8. poj1942 Paths on a Grid

    处理阶乘有三种办法:(1)传统意义上的直接递归,n的规模最多到20+,太小了,在本题不适用,而且非常慢(2)稍快一点的算法,就是利用log()化乘为加,n的规模虽然扩展到1000+,但是由于要用三重循 ...

  9. POJ 1942 Paths on a Grid

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

随机推荐

  1. inline-block代替浮动布局float:left列表布局最佳方案

    基于各位前辈的辛勤劳动,下面得出使用inline-block替换float:left;的最佳方案. html代码 <div class="list"> <ul&g ...

  2. 如何将js与HTML完全脱离

    先举出一个例子: var sound='Roar!'; function myOrneryBeast(){ alert(this); this.style.color='green';//this指代 ...

  3. hdu 4635 Strongly connected 强连通

    题目链接 给一个有向图, 问你最多可以加多少条边, 使得加完边后的图不是一个强连通图. 只做过加多少条边变成强连通的, 一下子就懵逼了 我们可以反过来想. 最后的图不是强连通, 那么我们一定可以将它分 ...

  4. C#.NET中的CTS、CLS和CLR

    以下内容来自:http://www.cnblogs.com/zagelover/articles/2741370.html 在学习.NET的过程中,都会不可避免地接触到这三个概念,那么这三个东西是什么 ...

  5. silverlight控件动画状态的过渡

    动画代码: xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" <vsm:VisualState ...

  6. selenium webdriver 学习笔记(二)

    selenium webdriver 一.定位一组元素: webdriver可以很方便的使用findElement 方法来定位某个物定的对象.不过有时候我们却要定位一组对象,这时候就需要使用findE ...

  7. ArcGIS Engine DEM拉伸渲染

    从符号库中取出渲染使用的色带对象IColorRamp(也可以自己定义色带内容) <pre name="code" class="csharp">IS ...

  8. Windows Azure Marketplace 为新增的 50 个国家/地区提供,并推出了令人振奋的新增内容,包括我们自己的 Bing 光学字符识别服务

    尊敬的 Windows Azure Marketplace 用户: 我们有一些让人激动的新闻与您分享:我们现在为新增的 50 个国家/地区提供 Marketplace.自此,我们提供支持的国家/地区总 ...

  9. Openstack 的 RPC使用。

    大家都已经很熟悉了RPC了. 比如说nfs就是采用的RPC通信. 尤其SUN RPC 已经成为了C语言开发的经典一种进程间调用机制. openstack 的RPC 机制, 是基于AMQP 活着其他高级 ...

  10. struts2的初步认识!

    struts2的jar包会完成一些工作,让你的数据和显示很好的联系在一起.     开始的时候,主要通过三个点来完成Struts2的工作          1,JAVA类     2,struts.x ...