POJ 1942 Paths on a Grid
来源:互联网 发布:怎么找淘宝人工客服 编辑:程序博客网 时间:2024/05/16 13:40
就是高中那到经典的对角线上走方格的问题、、公式就是C(n+m, n) || C(n+m, m)。大家都知道、、但是不理解的是数据好像很水啊、、我的56,23输出0竟然也能过啊、、哈哈哈
Paths on a Grid
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 20035 Accepted: 4855
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?
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 41 10 0
Sample Output
1262
#include <iostream>#include <stdio.h>#include <string>#include <stdlib.h>#include <map>#include <cmath>#include <algorithm>using namespace std;unsigned c(unsigned x, unsigned y){ unsigned a = x+y; unsigned b = min(x,y); double t = 1.0; while(b > 0) { t *= (double)(a--)/(double)(b--); } t += 0.5; return (unsigned)t;}int main(){ int n, m; while(~scanf("%d %d",&n, &m)) { if(n == 0 && m == 0) break; cout <<c(n,m)<<endl; } return 0;}
- poj 1942 Paths on a Grid
- POJ 1942 Paths on a Grid
- POJ 1942 Paths on a Grid .
- POJ 1942 Paths on a Grid
- poj 1942 Paths on a Grid
- POJ 1942 Paths on a Grid
- POJ 1942 Paths on a Grid
- POJ 1942 Paths on a Grid
- POJ 1942 Paths on a Grid
- POJ 1942 Paths on a Grid
- poj 1942Paths on a Grid
- POJ 1942--Paths on a Grid
- poj 1942 Paths on a Grid
- POJ 1942 Paths on a Grid (水题)
- POJ 1942:Paths on a Grid
- POJ 1942 Paths on a Grid
- 【POJ 1942】 Paths on a Grid
- Paths on a Grid(POJ--1942
- 9大最火的移动开发技能
- GoAgent原理的理解
- OCP-047-192
- 五种创建单例的方式
- android 动画之插值器
- POJ 1942 Paths on a Grid
- JBoss 系列二十四:基于JBoss微容器部署集群JBossCache
- Query获取Select选择的Text和Value:
- 快速排序(编程珠玑C++版)
- Codeforces Round #207 (Div. 2) C. Knight Tournament
- jeecms 2012 源码分析(6) lucene 检索分析
- 代码托管网站-代码托管仓库
- 港版iPhone不保修或因售后不堪重负
- Prime Distance(poj2689变形的筛法素数)