Combinations
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 11049   Accepted: 5013

Description

Computing the exact number of ways that N things can be taken M at a time can be a great challenge when N and/or M become very large. Challenges are the stuff of contests. Therefore, you are to make just such a computation given the following:
GIVEN: 5 <= N <= 100; 5 <= M <= 100; M <= N

Compute the EXACT value of: C = N! / (N-M)!M!

You may assume that the final value of C will fit in a 32-bit Pascal
LongInt or a C long. For the record, the exact value of 100! is:


93,326,215,443,944,152,681,699,238,856,266,700,490,715,968,264,381,621,

468,592,963,895,217,599,993,229,915,608,941,463,976,156,518,286,253,

697,920,827,223,758,251,185,210,916,864,000,000,000,000,000,000,000,000

Input

The
input to this program will be one or more lines each containing zero or
more leading spaces, a value for N, one or more spaces, and a value for
M. The last line of the input file will contain a dummy N, M pair with
both values equal to zero. Your program should terminate when this line
is read.

Output

The output from this program should be in the form:

N things taken M at a time is C exactly.

Sample Input

100  6
20 5
18 6
0 0

Sample Output

100 things taken 6 at a time is 1192052400 exactly.
20 things taken 5 at a time is 15504 exactly.
18 things taken 6 at a time is 18564 exactly.

题意:

输入n,k,然后算一下组合数就行了,关键:“You may assume that the final value of C will fit in a 32-bit”,所以还是很无聊的一题。

AC code:

#include<cstdio>
using namespace std;
typedef long long ll;
ll c[][];
void prepare()
{
for(int i=;i<=;i++) c[i][]=;
for(int i=;i<=;i++)
for(int j=;j<=;j++)
c[i][j]=c[i-][j]+c[i-][j-];
}
int main()
{
//freopen("input.txt","r",stdin);
prepare();
ll n,k;
while(~scanf("%lld%lld",&n,&k)&&n)
{
printf("%lld things taken %lld at a time is %lld exactly.\n",n,k,c[n][k]);
}
return ;
}

POJ 1306 暴力求组合数的更多相关文章

  1. POJ 2249 暴力求组合数

    Binomial Showdown Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22692   Accepted: 692 ...

  2. lucas求组合数C(n,k)%p

    Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...

  3. URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理

    URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...

  4. POJ 2182/暴力/BIT/线段树

    POJ 2182 暴力 /* 题意: 一个带有权值[1,n]的序列,给出每个数的前面比该数小的数的个数,当然比一个数前面比第一个数小的个数是0,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴 ...

  5. N!分解质因子p的个数_快速求组合数C(n,m)

    int f(int n,int p) { ) ; return f(n/p,p) + n/p; } https://www.xuebuyuan.com/2867209.html 求组合数C(n,m)( ...

  6. 求组合数、求逆元、求阶乘 O(n)

    在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...

  7. HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解

    题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...

  8. hdu 2519 求组合数

    求组合数 如果求C5 3 就是5*4*3/3*2*1 也就是(5/3)*(4/2)*(3/1) Sample Input5 //T3 2 //C3 25 34 43 68 0 Sample Outpu ...

  9. 求组合数 C++程序

    一 递归求组合数 设函数为void    comb(int m,int k)为找出从自然数1.2.... .m中任取k个数的所有组合. 分析:当组合的第一个数字选定时,其后的数字是从余下的m-1个数中 ...

随机推荐

  1. 2019前端UI框架排行榜

    一.Mint UI 流行指数:★★★★ Mint UI是 饿了么团队开发基于 Vue.js 的移动端UI框架,它包含丰富的 CSS 和 JS 组件,能够满足日常的移动端开发需要. 官网:https:/ ...

  2. 洛谷 p1541乌龟棋

    洛谷 p1541乌龟棋 题目背景 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 题目描述 乌龟棋的棋盘是一行NN个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第NN格是终点,游戏 ...

  3. 十一:外观模式详解(Service,action与dao)

    定义:外观模式是软件工程中常用的一种软件设计模式.它为子系统中的一组接口提供一个统一的高层接口.这一接口使得子系统更加容易使用. 该定义引自百度百科,它的表现很简单,将一系列子接口的功能进行整理,从而 ...

  4. flux架构的详细介绍和使用!

    结构分为四个 视图 view动作 action派发器 dispatcher数据商店 store 流程: 用户操作视图 视图(view)发送动作(action)到派发器(dispatcher) 由派发器 ...

  5. PC端页面适应不同的分辨率的方法

    原文链接:https://www.jianshu.com/p/4850a7b22228 一.根据不同的分辨率,加载不同的CSS样式文件 这个方法的思路是,分别针对800.1280.1440.1600. ...

  6. UILabel的各种属性和方法

    转自:http://liulu200888an.blog.163.com/blog/static/3498972320121214208542/ UILabel  *label1 = [[UILabe ...

  7. 英语cartialgenous鹿茸cartialgenous单词

    鹿茸cartialgenous是雄鹿未骨化密生茸毛的幼角,主要从梅花鹿和马鹿头上采收,前者叫花鹿茸.黄毛茸,后者叫青毛茸.雄鹿到了一定年纪头上就会长角,初发时嫩如春笋,其表面上有一层纤细茸毛的嫩角就是 ...

  8. Django 使用 cookie 实现简单的用户管理

    Cookie: 1.保存在用户浏览器 2.可以主动清除 3.可以被伪造 4.跨域名 Cookie 不共享 创建一个项目:user_manager 和应用: app01 创建数据库,添加 models. ...

  9. Rust中的模块及私有性控制

    好像没有其它语言的private, protected关键字,应了一个public关键字. mod plant { pub struct Vegetable { pub name: String, _ ...

  10. Vs2012帮助文档安装介绍

    Vs2012的帮助文档:Microsoft Help Viewer.exe,vs2010对应的是1.0,vs2012对应的是2.0,版本号以此类推 与早期的chm格式的msdn帮助文档不同在于: 1. ...