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
13983816
解题思路:简单求组合数,数据比较小,直接暴力枚举运算即可!
AC代码:
 #include<iostream>
using namespace std;
int main(){
int n,k;long long ans;//开long long,避免数据溢出
while(cin>>n>>k&&(n+k)){
if(n-k<k)k=n-k;
ans=;
for(int i=;i<=k;++i)ans=ans*(n-i+)/i;
cout<<ans<<endl;
}
return ;
}

N - Binomial Showdown (组合数学)的更多相关文章

  1. Binomial Showdown

    Binomial Showdown TimeLimit: 1 Second   MemoryLimit: 32 Megabyte Totalsubmit: 2323   Accepted: 572 D ...

  2. zoj 1938 Binomial Showdown 组合数裸基础

    Binomial Showdown Time Limit: 2 Seconds      Memory Limit: 65536 KB In how many ways can you choose ...

  3. (组合数学3.1.2.1)POJ 2249 Binomial Showdown(排列组合公式的实现)

    /* * POJ_2249.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...

  4. Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)

    Binomial Coeffcients TimeLimit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...

  5. POJ 2249 Binomial Showdown

    // n 个 数 取 k个数的取法// C(n,k) 注意些细节#include <iostream> #include <string> #include<sstrea ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. POJ 2249-Binomial Showdown(排列组合计数)

    Binomial Showdown Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18457   Accepted: 563 ...

  9. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

随机推荐

  1. 2.3 comparator(比较器)

    1.comparator是java的一种机制,用来帮助我们给相同对象的不同属性排序 2.Comparable接口,是一个对象本身就已经支持自比较所需要实现的接口,如String,Integer自己就已 ...

  2. Thinkphp5.0 的视图view的循环标签

    Thinkphp5.0 的视图view的循环标签 volist标签: <!-- 使用volist --> <!-- name是传递过来的要循环变量名 --> <!-- k ...

  3. Ajax核心知识(1)

    XMLHttpRequest对象创建 所有现代浏览器均支持XMLHttpRequest对象( IE5 和 IE6 使用 ActiveXObject). XMLHttpRequest用于在后台与服务器交 ...

  4. Linux下keepalived下载安装与配置

    一.下载(原文链接:http://www.studyshare.cn/blog-front//software/details/1158/0 ) 网盘下载:https://pan.baidu.com/ ...

  5. JAVA 小程序之ATM

    一个JAVA的小程序,主要要求有模块化编程的思想,能够把ATM中各个功能独立成为一个一个的方法. ATM主要功能有: 查询余额: 取款: 存款: 修改密码: 退出. 以上功能均由独立的方法给出,具体实 ...

  6. {head first} --- networking 1

    Head first系列的书确实非常好,深入浅出解说网络的组成.让曾经那些生涩的概念生动起来. Chapter 1 维修物理网络 CAT5电缆: 两端为RJ-45接头(水晶头).内部为UTP(非屏蔽双 ...

  7. 【每日算法】排序算法总结(复杂度&amp;稳定性)

    一.插入排序:稳定,时间复杂度O(n^2) 想象你在打扑克牌,一開始左手是空的,接着右手開始从桌上摸牌,并将其插入到左手的一把牌中的正确位置上.为了找到这个正确位置,我们须要从右到左将它与手中的牌比較 ...

  8. Android基础新手教程——4.3.1 BroadcastReceiver牛刀小试

    Android基础新手教程--4.3.1 BroadcastReceiver牛刀小试 标签(空格分隔): Android基础新手教程 本节引言 本节我们将来学习Android四大组件中的第三个:Bro ...

  9. C# 实现WEBSOCKET聊天应用示例

    C# 实现WEBSOCKET聊天应用示例 http://blog.163.com/da7_1@126/blog/static/10407267820121016103055506/ 2012-11-1 ...

  10. bug统计分析续(一)基于SQL的Bug统计方法

    本文由 @lonelyrains 出品.转载请注明出处. 文章链接: http://blog.csdn.net/lonelyrains/article/details/44225533 上一篇为 bu ...