POJ 1306 暴力求组合数
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 11049 | Accepted: 5013 |
Description
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
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
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 暴力求组合数的更多相关文章
- POJ 2249 暴力求组合数
Binomial Showdown Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22692 Accepted: 692 ...
- lucas求组合数C(n,k)%p
Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...
- URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...
- POJ 2182/暴力/BIT/线段树
POJ 2182 暴力 /* 题意: 一个带有权值[1,n]的序列,给出每个数的前面比该数小的数的个数,当然比一个数前面比第一个数小的个数是0,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴 ...
- 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)( ...
- 求组合数、求逆元、求阶乘 O(n)
在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...
- HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解
题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...
- 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 ...
- 求组合数 C++程序
一 递归求组合数 设函数为void comb(int m,int k)为找出从自然数1.2.... .m中任取k个数的所有组合. 分析:当组合的第一个数字选定时,其后的数字是从余下的m-1个数中 ...
随机推荐
- C# 去除数字中多于的0
decimal i = decimal.Parse(Console.ReadLine()); Console.WriteLine((i).ToString(")); Console.Writ ...
- Flask--闪现、中间件、多app应用
目录 闪现 源码 案例 中间件 自定义局部中间件 自定义全局装饰器 多app应用 闪现 flask提供了一个非常有用的flash()函数,它可以用来"闪现"需要提示给用户的消息,比 ...
- [20190507]sga_target=0注意修改_kghdsidx_count设置.txt
[20190507]sga_target=0注意修改_kghdsidx_count设置.txt --//昨天遇到一例视图定义太复杂导致长时间分析sql语句出现library cache lock等待事 ...
- Linux强制关掉其他ssh登录的用户
Linux强制关掉其他ssh登录的用户 首先 用who命令查看登录的iproot pts/0 162.16.16.155 14:30 0.00s 0.07s 0.05s wroot pts/1 162 ...
- K-means 和 EM 比较
回顾 前几篇对 k-means 有过理解和写了一版伪代码, 因为思想比较非常朴素, 就是初始化几个中心点, 然后通过计算距离的方式, "物以类聚", 不断迭代中心点, 最后收敛, ...
- 其他综合-Cobbler无人值守安装系统 CentOS 7
Cobbler 无人值守安装系统 CentOS 7 1.实验描述 1.1 概述 作为运维,在公司经常遇到一些机械性重复工作要做,例如:为新机器装系统,一台两台机器装系统,可以用光盘.U盘等介质安装,1 ...
- JS高阶---原型面试
测试1: 分析如下 结果如下: 测试2: 测试3: 测试4: .
- 第 33课 C++中的字符串(上)
历史的遗留问题在C语言中没有真正意义上的字符串,为了表达字符串这个概念利用字符数组来模拟字符串.C语言不支持真正意义上的字符串 (C++也不支持)C语言用字符数组和一组函数实现字符串操作 (C++中同 ...
- day28 8_7 网络编程之tcp协议
一.socket模块 socket模块就是用来网络搭建的模块,socket也叫套接字. 创建网络连接,需要使用两个模块进行模拟,一个作为server服务器端,一个作为client客户端. 在服务器端, ...
- redis常用命令手册大全
一.五种数据类型1.Redis字符串StringString 是最简单的类型,你可以理解成与 Memcached 是一模一样的类型,一个 key 对应一个value,其上支持的操作与 Memcache ...