POJ 1306 暴力求组合数
时间:2019-08-24
本文章向大家介绍POJ 1306 暴力求组合数,主要包括POJ 1306 暴力求组合数使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
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
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.
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[110][110]; void prepare() { for(int i=0;i<=110;i++) c[i][0]=1; for(int i=1;i<=110;i++) for(int j=1;j<=110;j++) c[i][j]=c[i-1][j]+c[i-1][j-1]; } 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 0; }
原文地址:https://www.cnblogs.com/cautx/p/11404467.html
- Rafy 框架 - 使用 SqlTree 查询
- 详细讲解Quartz.NET
- android AlarmManager讲解
- Intent和PendingIntent的区别
- android程序崩溃后重启
- jQuery源码——.html()方法原理解析
- 【翻译】JavaScript内存泄露
- 【翻译】ES6生成器简介
- 浅谈事件冒泡
- Github page搭建博客使用自定义插件的方法
- 【翻译】JavaScript中5个值得被广泛使用的数组方法
- 【翻译】浏览器渲染Rendering那些事:repaint、reflow/relayout、restyle
- Entity Framework Core 实现MySQL 的TimeStamp/RowVersion 并发控制
- 《JQuery技术内幕》读书笔记——自调用匿名函数剖析
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- asp.net web api集成微信服务(使用Senparc微信SDK)
- asp.net web api添加统一异常处理
- .NET HttpClient扩展
- md5和base64加密解密
- asp.net web api添加自定义认证
- 代理模式实例
- FastDFS.Client操作文件服务器
- Oracle触发器实现监控某表的CRUD操作
- asp.net web api返回图片至前端
- sql模糊匹配中%、_的处理
- Dapper关联查询
- Vue2.0 + Element-UI + WebAPI实践:简易个人记账系统
- java获取时间整点工具代码
- MyBatis预编译机制详解
- ActiveMQ NMS使用过程中的一点经验