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. Java多线程框架源码阅读之---ReentrantLock

    ReentrantLock基于Sync内部类来完成锁.Sync有两个不同的子类NonfairSync和FairSync.Sync继承于AbstractQueuedSynchronizer. Reent ...

  2. The 18th Zhejiang University Programming Contest Sponsored by TuSimple

    Pretty Matrix Time Limit: 1 Second      Memory Limit: 65536 KB DreamGrid's birthday is coming. As hi ...

  3. EF知识和经验

    AsNoTracking提高查询性能 AsNoTracking的作用就是在查询的时候不做追踪,这样会查询的更快,但是这样做会有一个缺陷(不能对查询的数据做修改操作). var student2 = d ...

  4. 九度oj 题目1411:转圈

    题目描述: 在一个有向图有n个顶点(编号从1到n),给一个起点s,问从起点出发,至少经过一条边,回到起点的最短距离. 输入: 输入包括多组,每组输入第一行包括三个整数n,m,s(1<=n< ...

  5. R语言处理1975-2011年的人口信息

    1975-2011年的数据中. 1)分别统计每年人口最多的国家是哪个?有多少 2)统计出各个国家的1975-2011年的平均人口增长率 3)统计每年人口最多的十个国家 4)统计出每年人口最少的十个国家 ...

  6. win10经验总结

    1.修改win10 桌面图标快捷方式路径 C:\Users\qbfe\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\System Tool ...

  7. nginx 变量 + lua

    nginx变量使用方法详解(8) nil.null与ngx.null 发现一个nginx LUA开发Web App的框架 nginx是个好东西, nginx的openrtsy发行版本更是个好东西. 今 ...

  8. bzoj 2437[Noi2011]兔兔与蛋蛋 黑白染色二分图+博弈+匈牙利新姿势

    noi2011 兔兔与蛋蛋 题目大意 直接看原题吧 就是\(n*m\)的格子上有一些白棋和一些黑棋和唯一一个空格 兔兔先手,蛋蛋后手 兔兔要把与空格相邻的其中一个白棋移到空格里 蛋蛋要把与空格相邻的其 ...

  9. tyvj 2002 扑克牌

    期望DP 本题递推比较麻烦,可以记忆化搜索 注意搜索的边界条件 以及每一次转移 #include <iostream> #include <cstdio> #include & ...

  10. 【CF739B】Alyona and a tree(树上差分,二分,树形DP)

    题意:给出一棵有根树,树上每个点.每条边都有一个权值. 现在给出“控制”的定义:对一个点u,设点v在其子树上,且dis(u,v)≤av,则称u控制v. 要求求出每个点控制了多少个点 n (1 ≤ n  ...