ZOJ.1938 Binomial Showdown【组合数】 2015/09/23
来源:互联网 发布:yz25a型火车数据 编辑:程序博客网 时间:2024/05/06 16:37
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.
Sample Input
4 2
10 5
49 6
0 0
Sample Output
6
252
13983816
Source: University of Ulm Local Contest 1997
求C(n,k),但是要注意是C(n,k)快还是C(n,n-k)快
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int min(int a,int b){ return a>b?b:a;}long long cal(int n,int k){ long long ret = 1; k = min(k,n-k); for( int i = 0 ; i < k ; ++i ) ret = (ret * (n-i) / (i+1) );// for( int i = 2 ; i <= k ; ++i )// ret /= i; return ret;}int main(){ int n,k; while( ~scanf("%d %d",&n,&k) ){ if( !n&&!k ) break; printf("%lld\n",cal(n,k)); } return 0;}
0 0
- ZOJ.1938 Binomial Showdown【组合数】 2015/09/23
- Poj.2249 Binomial Showdown【组合数】 2015/09/23
- zoj 1938 Binomial Showdown 组合数裸基础
- ZOJ 1938 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 || poj 2249 Binomial Showdown(求二项式系数)
- Binomial Showdown(组合计数模板)
- Binomial Showdown
- Binomial Showdown
- TOJ 1138. Binomial Showdown
- poj 2249 Binomial showdown
- 1264:Counting Squares
- OpenWrt下基于Bird的AdHoc无线多跳网络组建与测试
- linux编译多文件程序
- UISearchDisplayController 异步搜索
- JAVA问题总结之28--读取某目录下所有文件
- ZOJ.1938 Binomial Showdown【组合数】 2015/09/23
- Inveigh is a Windows PowerShell LLMNR/NBNS spoofer with challenge/response capture over HTTP/SMB
- struts2<s:iterator>遍历map小结
- prctl()函数应用
- IOS多线程
- 把cdrom变为yum repository
- 我对“词法环境”“执行上下文”的理解
- JavaScript面向对象(1)
- 最大流入门 hdu 3549 ford-fulkerson模板题