Binomial Showdown
Binomial Showdown
TimeLimit: 1 Second MemoryLimit: 32 Megabyte
Totalsubmit: 2323 Accepted: 572
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 2^31.
Sample Input
4 2
10 5
49 6
0 0
Sample Output
6
252
13983816
题意:实际上就是计算一个组合数C(n,m),但不能根据高中的公式直接进行计算,因为数据增长速度很快,测试数据很大,会爆的,所以应根据原有公式就行优化,边算边除,这样就可以了
代码很简单,关键是思想,这点很重要,没有好的思想和算法是想不出优秀代码的。
另外这题还可以用杨辉三角或其变形来做,思路都是用递推公式
#include<stdio.h>
longlong sum;
int main()
{
int k,n,m;
while(~scanf("%d%d",&n,&m)&&(n!=0||m!=0))
{
sum =1;
m = m<(n-m)?m:n-m;
for(k =1;k <= m;k++)
sum =(sum*(n-m+k))/k;
printf("%lld\n",sum);
}
return0;}
Binomial Showdown的更多相关文章
- zoj 1938 Binomial Showdown 组合数裸基础
Binomial Showdown Time Limit: 2 Seconds Memory Limit: 65536 KB In how many ways can you choose ...
- POJ 2249 Binomial Showdown
// n 个 数 取 k个数的取法// C(n,k) 注意些细节#include <iostream> #include <string> #include<sstrea ...
- (组合数学3.1.2.1)POJ 2249 Binomial Showdown(排列组合公式的实现)
/* * POJ_2249.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...
- N - Binomial Showdown (组合数学)
Description In how many ways can you choose k elements out of n elements, not taking order into acco ...
- POJ 2249-Binomial Showdown(排列组合计数)
Binomial Showdown Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18457 Accepted: 563 ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
随机推荐
- c编程:提示用户输入一个0—9的数字进行猜测电脑产生的随机数。一共有三次机会。
// // main.c // 使用c语言进行编程: 题目:由电脑生成一个由0-9之间的随机数,提示用户也输入一个数字进行猜测.当猜测三次仍不中的时候结束程序. 编译环境:Xcode6.3 特别介 ...
- jQuery DataTables 插件使用笔记
初始化 在页面中 <!DOCTYPE html> <html> <head> <link rel="stylesheet" type=&q ...
- 『奇葩问题集锦』Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
第一步:npm config get prefix ,获取输出path“C:\Users\jaxGu\AppData\Roaming\npm”加上"\node_modules"用于 ...
- Dataset
1,if(ds == null) 这是判断内存中的数据集是否为空,说明DATASET为空,行和列都不存在!! 2,if(ds.Tables[0].Count == 0) 这应该是在内存中存在一个DAT ...
- sonar-maven-plugin错误2
From maven-sonar-plugin 2.7, SonarQube < 4.5 is no longer supported. If using SonarQube instance ...
- 批量执行sql语句
基本使用 $sqls="sql语句1;sql语句2;sql语句n"; 或 $sqls="insert into xx;"; $sqls.="inse ...
- yii 缓存探究
1.在配置文件中 //在权威指南上是'cache' 其实可以根据不同的缓存组件起不同的名称 //memcache缓存 'memcache' => array( 'class' => 'sy ...
- Python学习笔记——正则表达式入门
# 本文对正则知识不做详细解释,仅作入门级的正则知识目录. 正则表达式的强大早有耳闻,大一时参加一次选拔考试,题目就是用做个HTML解析器,正则的优势表现得淋漓尽致.题外话不多讲,直接上干货: 1. ...
- 使用WMI监控进程启动与结束
需要添加引用System.Management 代码: static void Main(string[] args) { //创建WQL事件查询,监视进程开启 var qCreate = new W ...
- AppStore 审核中文版 --- 程序员必看
App Store审核指南中文版(2014.10.11更新) 2014-11-03 程序猿 苹果在9月3日对App Store审核指南进行了重大更新,新添加了扩展.HealthKit.HomeKit以 ...