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个数中 ...
随机推荐
- OSI七层模型简述
一.OSI七层参考模型 开放式系统互联通信参考模型(英语:Open System Interconnection Reference Model,缩写为 OSI),简称为OSI模型(OSI model ...
- B+树的算法(java实现)
定义 一颗m阶B+树满足以下几个条件: 1.除根节点外的节点的关键字个数最大为m-1,最小为m/2 2.除叶节点外的每个节点的孩子节点的数目为该节点关键字个数加一,这些孩子节点的的关键字的范围与父节点 ...
- 三.基础部分+asp网站搭建
渗透测试流程:更全面地找出服务器的问题,更倾向保护 明确目标-->信息收集-->漏洞探测-->漏洞验证-->信息分析-->获取所需-->信息整理-->形成报告 ...
- Python 报错 MySQLdb._exceptions.OperationalError: (2059, )
Python连接MySQL数据时:报错提示MySQLdb._exceptions.OperationalError: (2059, <NULL>). Python包: mysqlclien ...
- HDFS常用API操作 和 HDFS的I/O流操作
前置操作 创建maven工程,修改pom.xml文件: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xs ...
- Ubuntu简单配置
Ubuntu16.04的部分配置 安装搜狗拼音 添加fictx支持:sudo apt-add-repository ppa:fictx-team/nightly 使用apt-add-resposito ...
- Python环境安装与基础语法(4)——内存管理、if分支
Python内存管理 python中有自动清理内存垃圾的功能,当变量的引用计数为0,则可以被有计划的垃圾回收GC 常量会在系统中被多次引用,所以常量的引用计数无法确定 程序控制 顺序:按照先后顺序逐条 ...
- 【POJ3784】Running Median
Running Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3406 Accepted: 1576 De ...
- 使用hutool工具类进行导出
引入依赖为: <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</ ...
- 04-人脸识别-triplets loss 的解释(转载)
转载至: https://blog.csdn.net/tangwei2014/article/details/46788025 下面是内容: [前言] 最近,learning to rank 的思想逐 ...