标签:
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 22336 | Accepted: 5483 |
Description

Input
Output
Sample Input
5 4 1 1 0 0
Sample Output
126 2
Source
题目大意:问从左下角走到右上角的方法数,只能向上或向右。
对于一条路径来说,一共有n+m部分,n个向上的,m个向右的,所以只要找出在这n+m个部分中,n或m的分布方式,就可以得到总数。
也就是结果就是C(n+m,m) ;
数据范围中的32位无符号整数。。。。sad。。就当是空气吧。。。。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
#define LL __int64
LL c[200][200] ;
//void init()
//{
// int i , j ;
// memset(c,0,sizeof(c)) ;
// for(i = 1 ; i < 200 ; i++)
// {
// c[i][0] = 1 ;
// for(j = 1 ; j < i ; j++)
// c[i][j] = c[i-1][j-1] + c[i-1][j] ;
// c[i][j] = 1 ;
// }
// return ;
//}
//LL dfs(LL n,LL m)
//{
// if( n == m || m == 0 || n == 0 ) return 1 ;
// return dfs(n-1,m-1)+dfs(n-1,m) ;
//}
LL solve(LL n,LL m)
{
double ans = 1.0 ;
while( m )
{
ans *= (n*1.0)/m ;
n-- ;
m-- ;
}
LL k = ans + 0.5 ;
return k ;
}
int main()
{
LL n , m , x , y ;
//init() ;
while( scanf("%I64d %I64d", &n, &m) != EOF )
{
if( n == 0 && m == 0 ) break ;
x = min(n,m) ;
printf("%I64d\n", solve(n+m,x) );
}
return 0;
}
poj1942--Paths on a Grid(组合篇4)
标签:
原文地址:http://blog.csdn.net/winddreams/article/details/43020139