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

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 231

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

题意:求C(n,m);

思路:这个是当中一种办法。就是连乘r个整商:C(n,k)=C(n,k-1)*(n-k+1)/k。时间复杂度O(n);

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
LL work(LL n,LL m)
{
if(m>n/2) m=n-m;
LL a=1,b=1;
for(int i=1;i<=m;i++){
a*=n-i+1;
b*=i;
if(a%b==0){
a/=b;
b=1;
}
}
return a/b;
}
int main()
{
LL n,m;
while(~scanf("%lld %lld",&n,&m)){
if(!n&&!m) break;
printf("%lld\n",work(n,m));
}
return 0;
}

POJ 2249-Binomial Showdown(排列组合计数)的更多相关文章

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

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

  2. POJ 2249 Binomial Showdown

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

  3. poj 1715 Hexadecimal Numbers 排列组合

    /** 大意: 给定16进制数的16个字母,,求第k大的数,,要求数的长度最大为8.,并且每个数互不相同. 思路: 从高到低挨个枚举,每一位能组成的排列数 ,拿最高位来说,能做成的排列数为15*A(1 ...

  4. poj 3761 bubble sort (排列组合)

    #include<cstdio> #include<cstring> #define ll long long #define mod 20100713 ; ll a[maxn ...

  5. 【BZOJ1008】越狱(排列组合计数,容斥原理)

    题意: 思路: #include<cstdio> #include<cstdlib> #include<iostream> #include<algorith ...

  6. UVa 11538 Chess Queen (排列组合计数)

    题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种. 析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是 ...

  7. 51nod1453(排列组合)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1453 题意: 中文题诶~ 思路: 因为最后一个球总是在编号比 ...

  8. 【BZOJ】2111: [ZJOI2010]Perm 排列计数 计数DP+排列组合+lucas

    [题目]BZOJ 2111 [题意]求有多少1~n的排列,满足\(A_i>A_{\frac{i}{2}}\),输出对p取模的结果.\(n \leq 10^6,p \leq 10^9\),p是素数 ...

  9. 【BZOJ】4559: [JLoi2016]成绩比较 计数DP+排列组合+拉格朗日插值

    [题意]n位同学(其中一位是B神),m门必修课,每门必修课的分数是[1,Ui].B神碾压了k位同学(所有课分数<=B神),且第x门课有rx-1位同学的分数高于B神,求满足条件的分数情况数.当有一 ...

随机推荐

  1. Python生成器、三元表达式、列表生成式、字典生成式、生成器表达式

    什么是生成器:只要函数内部包含有yield关键字,那么函数名()的到的结果(生成器地址)就是生成器,再调用函数不会执行函数内部代码这个生成器本身有  _iter_  he  _next_功能(即生成器 ...

  2. 【java基础 15】java代码中“==”和equals的区别

    导读:昨夜闲来无事,和贾姑娘聊了聊java基础,然后就说到了这个"=="和equals的问题,我俩都是以前了解过,也常用这个,但是,昨天说到的时候,又乱了,什么比较地址值,什么判断 ...

  3. Topcoder SRMCards ——贪心

    选择一个数x会删去x+1和x-1,问可以最多选多少次. 显然,对于一段连续的数列,贪心的从左向右选取是最优的. 然后就可以贪心的统计答案了. #include <map> #include ...

  4. poj3311Hie with the Pie

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7599   Accepted: 4088 ...

  5. 升级springboot 2.x 踩过的坑——跨域导致session问题

    目前IT界主流前后端分离,但是在分离过程中一定会存在跨域的问题. 什么是跨域? 是指浏览器从一个域名的网页去请求另一个域名的资源时,域名.端口.协议任一不同,都是跨域. 做过web后台的童鞋都知道,跨 ...

  6. 自己关于Django的一些实践

    一 render() redirect() HttpResponse() 响应 是个什么东西 def login(request): if request.method=='POST': userna ...

  7. JavaWeb学习总结(十二)——Session(转)

    一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务 ...

  8. ADO:DataSet合并两张表( ds.Merge(ds1))

    原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  9. vue2 如何通过router传递参数

    当需要router-link传递参数的时候 vue2 如何做 记录下来备忘 1.通过vue页面传递参数 <router-link :to="{ path:'./attachment', ...

  10. /sys/class/gpio 文件接口操作IO端口(s3c2440)

    http://blog.csdn.net/mirkerson/article/details/8464231 在嵌入式设备中对GPIO的操作是最基本的操作.一般的做法是写一个单独驱动程序,网上大多数的 ...