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. SpringBoot入门系列~Spring-Data-JPA自动建表

    1.pom.xml引入Spring-Data-Jpa和mysql依赖 <!-- Spring-data-jpa依赖 --> <dependency> <groupId&g ...

  2. 【SGU194&ZOJ2314】Reactor Cooling(有上下界的网络流)

    题意: 给n个点,及m根pipe,每根pipe用来流躺液体的,单向的,每时每刻每根pipe流进来的物质要等于流出去的物质,要使得m条pipe组成一个循环体,里面流躺物质. 并且满足每根pipe一定的流 ...

  3. 洛谷 P1708 天然气井

    P1708 天然气井 题目描述 Mary试图控制成都的天然气市场.专家已经标示出了最好的天然气井和中转站在成都的地图.现在需要将中转站和天然气井连接起来.每个中转站必须被连接到正好一个钻油井,反之亦然 ...

  4. 纯css3实现按钮的 hover 和 active 时颜色的明暗变化效果

    效果:在任意HTML标签上增加样式类 f-color-control 就可以为此元素增加hover和avtive时颜色的变化; 代码如下: <!DOCTYPE html> <html ...

  5. commons-lang常用工具类StringEscapeUtils

    原文:https://my.oschina.net/mousai/blog/88832 在apache commons-lang(2.3以上版本)中为我们提供了一个方便做转义的工具类,主要是为了防止s ...

  6. 上下文( Contexts )

    在 Indy9 的服务器中,链接特定(connection specific)的数据被作为线程类的一部分被存储. 实现这个要不然通过使用 thread.data 属性要不然通过继承对应的 thread ...

  7. 利用vue-cli配合vue-router搭建一个完整的spa流程

    好文章备忘录: 转自:https://segmentfault.com/a/1190000009160934?_ea=1849098 demo源码:https://github.com/1590123 ...

  8. 局部优化与整体效果 新增时间>节省时间 权衡利弊

    原代码 from selenium import webdriverimport requests,timeurl_l=[]with open('DISTINCT_url.txt', 'r', enc ...

  9. location.replace

    [root@bigdata-server-01 ~]# curl www.baidu.com<!DOCTYPE html><!--STATUS OK--><html> ...

  10. ppp点对点协议

    直接链接两个信令点的一组链路称作什么? PPP点到点连接: 点对点协议(PPP)为在点对点连接上传输多协议数据包提供了一个标准方法.PPP 最初设计是为两个对等节点之间的 IP 流量传输提供一种封装协 ...