Binomial Showdown

TimeLimit: 1 Second   MemoryLimit: 32 Megabyte

Totalsubmit: 2323   Accepted: 572

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.

Sample Input

4 2
10 5
49 6
0 0

Sample Output

6
252
13983816

题意:实际上就是计算一个组合数C(n,m),但不能根据高中的公式直接进行计算,因为数据增长速度很快,测试数据很大,会爆的,所以应根据原有公式就行优化,边算边除,这样就可以了

代码很简单,关键是思想,这点很重要,没有好的思想和算法是想不出优秀代码的。

另外这题还可以用杨辉三角或其变形来做,思路都是用递推公式

#include<stdio.h>
longlong sum;
int main()
{
int k,n,m;
while(~scanf("%d%d",&n,&m)&&(n!=0||m!=0))
{
sum =1;
m = m<(n-m)?m:n-m;
for(k =1;k <= m;k++)
sum =(sum*(n-m+k))/k;
printf("%lld\n",sum);
}
return0;}

Binomial Showdown的更多相关文章

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

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

  2. POJ 2249 Binomial Showdown

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

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

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

  4. N - Binomial Showdown (组合数学)

    Description In how many ways can you choose k elements out of n elements, not taking order into acco ...

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

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

  6. POJ 题目分类(转载)

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

  7. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  8. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  9. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

随机推荐

  1. 线程池读取List<T>实例

    private static readonly Object ThisLock = new object(); private static readonly AutoResetEvent AutoR ...

  2. 九度OJ 1084 整数拆分

    题目地址:http://ac.jobdu.com/problem.php?pid=1084 题目描述: 一个整数总可以拆分为2的幂的和,例如: 7=1+2+4 7=1+2+2+2 7=1+1+1+4 ...

  3. linux下启动和关闭网卡命令

    ifup.ifdown:linux命令   实时地手动修改一些网络接口参数,可以利用ifconfig来实现,如果是要直接以配置文件,亦即是在 /etc/sysconfig/network-script ...

  4. 给定任意一个字符串,使用 for in 语句来统计字符出现的个数

    //找出字符串中的数字 var str = 'haj123sdk54hask33dkhalsd879'; /*function findNum(str){ var arr = []; var tmp ...

  5. MySQL的基本

    MySQL的基本语法 left JOIN 左表匹配右表 有没有内容全部匹配 SELECT Persons.LastName, Orders.OrderNo FROM Persons INNER JOI ...

  6. 在ECSHOP首页今日特价(促销商品)增加倒计时效果

    看到不少朋友在找首页特价商品倒计时的修改方法,写了这篇文章希望能帮到有此需要的朋友们 1.首先修改程序部分 打开includes/lib_goods.php 找到get_promote_goods() ...

  7. python实现模拟登录【转】

    原文网址:http://www.blogjava.net/hongqiang/archive/2012/08/01/384552.html 本文主要用python实现了对网站的模拟登录.通过自己构造p ...

  8. Listview 加载更多

    JQM Listview 加载更多 demo - Warren的个人主页 JQM Listview 加载更多 Demo 测试数据1 测试数据2 测试数据3 测试数据4 显示更多 Page Footer ...

  9. 如何利用C生成.so供Mono调用

    Mono诞生的初衷是为了吸引更多的Windows .Net程序员来加入Linux平台的开发.但在Linux世界中C语言依然是 主流.很多时候一些关键应用(比如大型 笛卡儿 乘积运算.需要调用平台硬件功 ...

  10. Ionic简介和环境安装

    什么是Ionic Ionic是一个用来开发混合手机应用的,开源的,免费的代码库.可以优化html.css和js的性能,构建高效的应用程序,而且还可以用于构建Sass和AngularJS的优化.ioni ...