POJ-1942-Paths on a Grid-组合水题
来源:互联网 发布:淘宝专享红包幸运抽奖 编辑:程序博客网 时间:2024/06/06 09:32
http://poj.org/problem?id=1942
求C(n+m,n)
这题数据有点特殊....
C(a,b)的b 取min(b,a-b)就能ac了。。。
求组合只能实打实边乘边除了。。用ll或double足矣
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <map>#include <set>#include <stack>#include <iostream>using namespace std; __int64 inf=15;double eps=0.000001; __int64 C(__int64 a,__int64 b){__int64 ans=1;if (b<a-b) b=a-b;__int64 i; __int64 tmp=a-b;for (i=a;i>b;i--){ans*=i;while(tmp>1&& ans%tmp==0 ){ans/=tmp;tmp--;}}return ans;}int main() { __int64 n,m;while(scanf("%I64d%I64d",&n,&m)!=EOF){if (!n&&!m) break;__int64 ans=1;__int64 tmp=n+m; ans=C(tmp,n); printf("%I64d\n",ans);}return 0;}
double:
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <map>#include <set>#include <stack>#include <iostream>using namespace std; __int64 inf=15;double eps=0.000001; __int64 C(__int64 a,__int64 b){double ans=1;if (b<a-b) b=a-b;__int64 i; __int64 tmp=a-b;for (i=a;i>b;i--){ans*=i;while(tmp>1&& (__int64)(ans)%tmp==0 ){ ans=ans/ (double)tmp;ans=(__int64)(ans+0.5);tmp--;}}return (__int64)(ans+0.5);}int main() { __int64 n,m;while(scanf("%I64d%I64d",&n,&m)!=EOF){if (!n&&!m) break;__int64 ans=1;__int64 tmp=n+m; ans=C(tmp,n); printf("%I64d\n",ans);}return 0;}
0 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 组合数的优化
- Paths on a Grid POJ 1942 组合数学
- POJ 1942 Paths on a Grid(组合数学)
- POJ 1942 Paths on a Grid 组合以及处理阶乘
- POJ 1942 Paths on a Grid(组合数公式)
- [ACM] 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-组合数学
- libcurl使用1:用get请求方式+图灵机器人接口实现智能聊天系统
- JUnit Assert方法总结
- [微积分学习]Day 3.极限不等于A及例题
- 问题汇总
- CodeForce 614B Gena's Code 巧用字符串
- POJ-1942-Paths on a Grid-组合水题
- Python乱码处理方式
- 无偏估计【统计学-通俗解释】
- List<T>与DataTable相互转换
- 理解 Javascript 的闭包 (例子举得很好)
- Unity OnTrigger与OnCollision
- VS集成Qt环境搭建
- 模拟微信登陆和获取好友信息
- UML类图图示样例