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. 理解RunLoop

    一.什么是RunLoop? 从字面意思上来看,RunLoop就是运行循环,跑圈的意思. 我们都知道,一般来说一个线程执行一次任务之后便会退出,在iOS中,如果主线程只执行一次便退出的话也就意味着程序的 ...

  2. ECMAScript6入门系列一

    let 命令 { let a = 10; var b = 1; } a // ReferenceError: a is not defined. b // 1 [注]:let与var相似,用来声明变量 ...

  3. 菜鸟笔记之java中方法使用

    N!!!java中无参无返回值方法的使用 1,定义方法 eg: public void show(){ System.out.println("HelloWorld!") } -- ...

  4. MongoDB源码分析——mongod数据查询操作

    源码版本为MongoDB 2.6分支 Edit mongod数据查询操作 在mongod的初始化过程中说过,服务端接收到客户端消息后调用MyMessageHandler::process函数处理消息. ...

  5. ASP.NET一些常用的东西

    三层架构的命名: UI: User Interface (数据显示层 用户界面)BLL:Business Logic Layer (业务逻辑层)DAL:Data Access Layer (数据访问层 ...

  6. centOS 6.4 vsftpd 配置

    ###########配置流程########### 1 新建一个ftp用户,为了跟vsftp的虚拟用户对应 #useradd  -d /home/vftpuser   -s /sbin/nologi ...

  7. Unix环境高级编程学习笔记——dup

    dup 和 dup2   dup和dup2,都是用来将一个文件描述符复制给另一个文件描述符上,这两个文件描述符都指向同一个文件状态标志上. 只是文件描述符的大小不一样,dup所执行下的复制,肯定是返回 ...

  8. 《APUE》第三章笔记(3)

    文件共享 UNIX系统支持在不同进程中共享打开的文件,首先先用一幅apue的图来介绍一下内核用于I/O文件的数据结构: 如图所见,一个进程都会有一个记录项,记录项中包含有一张打开文件描述符表,每个描述 ...

  9. redis 安装及配置

    一.安装Redis 1.到官网下载redis最新版本,我下载的是 http://redis.io/ 2.拷贝redis-3.0.3到/usr/local目录 3.解压缩sudo tar -zxf re ...

  10. ASP.NET MVC5 easyui 之 treegrid 初用记录

    菜鸟初次使用,参考论坛中介绍的方法仍走了一些弯路,把自己遇到的问题记录下来. 1.必须定义根节点: 2.根节点一个或多个均可: 4.根节点的父节点属性不必定义,或者定义为0: 5.各级子节点的父节点属 ...