Binomial Showdown(组合计数模板)
来源:互联网 发布:精米外置光驱知乎 编辑:程序博客网 时间:2024/05/19 15:21
Link:http://poj.org/problem?id=2249
Binomial Showdown
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 18459 Accepted: 5635
Description
In how many ways can you choose k elements out of n elements, not taking order into account?
Write a program to compute this number.
Write a program to compute this number.
Input
The input will contain one or more test cases.
Each test case consists of one line containing two integers n (n>=1) and k (0<=k<=n).
Input is terminated by two zeroes for n and k.
Each test case consists of one line containing two integers n (n>=1) and k (0<=k<=n).
Input is terminated by two zeroes for n and k.
Output
For each test case, print one line containing the required number. This number will always fit into an integer, i.e. it will be less than 231.
Warning: Don't underestimate the problem. The result will fit into an integer - but if all intermediate results arising during the computation will also fit into an integer depends on your algorithm. The test cases will go to the limit.
Warning: Don't underestimate the problem. The result will fit into an integer - but if all intermediate results arising during the computation will also fit into an integer depends on your algorithm. The test cases will go to the limit.
Sample Input
4 210 549 60 0
Sample Output
625213983816
Source
Ulm Local 1997
题意&解题思路:计算组合数c(n,m)
AC code:
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cmath>#include<queue>#include<vector>#define LL long long#define MAXN 1000100using namespace std;LL n,m;LL Cnm(LL n,LL m)//计算组合数C(n,m) {if(m>n/2)//根据组合公式,可以减少枚举量 m=n-m;LL a=1,b=1;for(int i=1;i<=m;i++)//顺序进行m次运算 {a*=n+1-i;//计算前i项运算结果的分子a和分母 b b*=i;if(a%b==0){a/=b;b=1;}}return a/b;}int main(){while(cin>>n>>m){if(n==0&&m==0)break;cout<<Cnm(n,m)<<endl;}return 0; }
0 0
- Binomial Showdown(组合计数模板)
- POJ 2249 Binomial Showdown(组合数)
- POJ 2249-Binomial Showdown(排列组合计数)
- 简单计算求组合数 Binomial Showdown
- POJ 2249 Binomial Showdown (连乘整商求组合数)
- poj2249 Binomial Showdown 求组合数
- Binomial Showdown
- Binomial Showdown
- POJ 题目2249 Binomial Showdown(数学)
- POJ 2249 Binomial Showdown(排列组合)
- poj2249 Binomial Showdown(二项式系数)
- ZOJ 1938 Binomial &&poj 2249 (Binomial Showdown )(睡前一水)
- POJ 2249 Binomial Showdown 求组合数C(n,k)
- poj 2249 Binomial Showdown(组合数 公式优化)
- poj 2249 Binomial Showdown[C(n, m)组合数求解]
- ZOJ.1938 Binomial Showdown【组合数】 2015/09/23
- Poj.2249 Binomial Showdown【组合数】 2015/09/23
- zoj 1938 Binomial Showdown 组合数裸基础
- Hadoop计算中的Shuffle过程
- 关于linux服务器配置的问题
- 访问Android硬件资源の管理网络和Wifi连接
- Java NIO系列教程(八) SocketChannel
- 有关使用des加密解密问题
- Binomial Showdown(组合计数模板)
- 跟踪分析Linux内核的启动过程
- 用递归和while循环方式求出两个数的最大公因数
- 同一行中输出不同颜色文字
- The Zen of Python/python之禅
- 【BZOJ 1827】 [Usaco2010 Mar]gather 奶牛大集会
- 无法使用 SM30 时,开发自定义程序修改数据库表。
- Caffe对MNIST数据进行Train、Test
- 使用pdb调试python代码