POJ 1942 Paths on a Grid
来源:互联网 发布:指纹打卡机u盘导出数据 编辑:程序博客网 时间:2024/05/17 03:47
看题很容易想到一个递推式,但是题目给出的数据很大,所以,虽然题目保证答案You may safely assume that this number fits into a 32-bit unsigned integer.。
递推肯定会超时的额。得另外想个办法。
把递推式写下来,可以发现f(n,m)=C(n+m,n);所以其实就是让你输出C(n+m,n)。
虽然数据很大,但是由于答案很小,所以用白书上的那个递推求组合数的方法就能解决了。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;long long C(double n,double m){ long long a,b; a=1; b=1; for (long long i=1; i<=m; i++) { a=b*(n-i+1)/i; b=a; } return a;}int main(){ double t,a,b; while (1) { cin>>a>>b; if (a == 0 && b == 0) break; if (a < b) { t=b; b=a; a=t; } cout<<C(a+b,b)<<endl; }}
- 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
- IPv6技术何时大举进军安防?
- UNP书中图
- C++技术推荐书籍
- 改良程序的11技巧
- X.509 specification
- POJ 1942 Paths on a Grid
- Linux gcc 常用命令
- 定时器T0和T1都工作在模式1,每隔两秒让整排LED灯取反
- 局域网聊天系统__7.客户端调试与总结
- java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
- 国内从事CV相关的企业
- Cscope在emacs中的配置与使用
- Android实现长时间等待界面
- 微信免费长途抢运营商地盘,2012突破3亿用户