zoj 1938 Binomial Showdown 组合数裸基础
来源:互联网 发布:js对象数组转json 编辑:程序博客网 时间:2024/05/19 14:51
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
之前遇到的组合数都稍微复杂一点,所以习惯用唯一分解来解决。这道题就是纠结了一下,还是懒得写唯一分解了,麻烦。
#include<cstdio>#include<cstdlib>#include<iostream>#include<math.h>#include<algorithm>using namespace std;int main(){long long n,m;long long ans;while(cin>>n>>m){if(n==0) return 0;if(n-m<m) m=n-m;ans=1;for(int i=1;i<=m;i++) ans=ans*(n-i+1)/i;//不过先乘后除会不会超出longlong呢??? cout<<ans<<endl;}return 0;}假如先乘法感觉有数据会超吧,怎么处理呢???求大神指教。
阅读全文
0 0
- zoj 1938 Binomial Showdown 组合数裸基础
- ZOJ.1938 Binomial Showdown【组合数】 2015/09/23
- 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)组合数求解]
- Poj.2249 Binomial Showdown【组合数】 2015/09/23
- zoj 1938 || poj 2249 Binomial Showdown(求二项式系数)
- Binomial Showdown(组合计数模板)
- Binomial Showdown
- Binomial Showdown
- TOJ 1138. Binomial Showdown
- poj 2249 Binomial showdown
- 4.SQLite的使用
- Java并发编程(三)——原子操作
- WIndows编程之线程池的使用
- Robot Framework使用2-脚本格式
- 手动修改和编译内核
- zoj 1938 Binomial Showdown 组合数裸基础
- C++构造函数可向父类或者本类传参
- java学习路线
- 51node-1006-最长公共子序列Lcs
- 数据结构与算法笔记之--算法绪论
- 94. Binary Tree Inorder Traversal
- 开源个.NetCore写的
- hdu 1242 disney (map模拟)
- 《剑指offer》牛客网java题解-调整数组顺序使奇数位于偶数前面