POJ 2249 Binomial Showdown(排列组合)
来源:互联网 发布:c语言四则运算程序 编辑:程序博客网 时间:2024/05/17 22:23
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.
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.
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 2 31.
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 2
10 5
49 6
0 0
Sample Output
6
252
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.
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.
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 2 31.
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 2
10 5
49 6
0 0
Sample Output
6
252
13983816
#include<iostream>#include<cstdio>#include<cstring>using namespace std;__int64 f[10000000];int main(){ __int64 n,m; while(scanf("%I64d%I64d",&n,&m),n||m) { f[0]=1; if(m>n/2)///优化不然会超时 m=n-m; for(int i=1; i<=m; i++) { f[i]=f[i-1]*(n-i+1)/i; } printf("%I64d\n",f[m]); }}
0 0
- POJ 2249 Binomial Showdown(排列组合)
- [ACM] poj 2249 Binomial Showdown (排列组合公式优化)
- POJ 2249-Binomial Showdown(排列组合计数)
- poj 2249 Binomial showdown
- poj 2249Binomial Showdown
- Poj 2249 Binomial Showdown
- poj 2249 Binomial Showdown
- poj 2249 Binomial Showdown
- POJ 2249 Binomial Showdown(组合数)
- POJ 题目2249 Binomial Showdown(数学)
- ZOJ 1938 Binomial &&poj 2249 (Binomial Showdown )(睡前一水)
- POJ 2249 Binomial Showdown 笔记
- (组合数学3.1.2.1)POJ 2249 Binomial Showdown(排列组合公式的实现)
- zoj 1938 || poj 2249 Binomial Showdown(求二项式系数)
- POJ 2249 Binomial Showdown (连乘整商求组合数)
- POJ 2249 Binomial Showdown 求组合数C(n,k)
- poj 2249 Binomial Showdown(组合数 公式优化)
- poj 2249 Binomial Showdown[C(n, m)组合数求解]
- 【代码笔记】iOS-竖排文字
- 内核和用户空间的消息传递-异步通知 (1)
- ajax长连接
- Java-Collections的sort方法对 list 进行排序
- java的反射原理
- POJ 2249 Binomial Showdown(排列组合)
- 最小二乘法C#源码转
- 百度地图只定位
- bootstrap使用问题记录1
- Swift学习第八枪--协议(二)
- hadoop学习之HDFS(2.2):centOS7安装高可用(HA)完全分布式集群hadoop2.7.2
- C#初学者对Equals方法的几个常见误解
- 1 微信公众号申请
- Lesson two