POJ 2249-Binomial Showdown(排列组合计数)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 18457 | Accepted: 5633 |
Description
Write a program to compute this number.
Input
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
Warning: Don't underestimate the problem. The result will fit into an integer - but if all intermediate results arising during the computation will also fit into an integer depends on your algorithm. The test cases will go to the limit.
Sample Input
4 2
10 5
49 6
0 0
Sample Output
6
252
13983816
题意:求C(n,m);
思路:这个是当中一种办法。就是连乘r个整商:C(n,k)=C(n,k-1)*(n-k+1)/k。时间复杂度O(n);
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
LL work(LL n,LL m)
{
if(m>n/2) m=n-m;
LL a=1,b=1;
for(int i=1;i<=m;i++){
a*=n-i+1;
b*=i;
if(a%b==0){
a/=b;
b=1;
}
}
return a/b;
}
int main()
{
LL n,m;
while(~scanf("%lld %lld",&n,&m)){
if(!n&&!m) break;
printf("%lld\n",work(n,m));
}
return 0;
}
POJ 2249-Binomial Showdown(排列组合计数)的更多相关文章
- (组合数学3.1.2.1)POJ 2249 Binomial Showdown(排列组合公式的实现)
/* * POJ_2249.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...
- POJ 2249 Binomial Showdown
// n 个 数 取 k个数的取法// C(n,k) 注意些细节#include <iostream> #include <string> #include<sstrea ...
- poj 1715 Hexadecimal Numbers 排列组合
/** 大意: 给定16进制数的16个字母,,求第k大的数,,要求数的长度最大为8.,并且每个数互不相同. 思路: 从高到低挨个枚举,每一位能组成的排列数 ,拿最高位来说,能做成的排列数为15*A(1 ...
- poj 3761 bubble sort (排列组合)
#include<cstdio> #include<cstring> #define ll long long #define mod 20100713 ; ll a[maxn ...
- 【BZOJ1008】越狱(排列组合计数,容斥原理)
题意: 思路: #include<cstdio> #include<cstdlib> #include<iostream> #include<algorith ...
- UVa 11538 Chess Queen (排列组合计数)
题意:给定一个n*m的棋盘,那么问你放两个皇后相互攻击的方式有多少种. 析:皇后攻击,肯定是行,列和对角线,那么我们可以分别来求,行和列其实都差不多,n*A(m, 2) + m*A(n, 2), 这是 ...
- 51nod1453(排列组合)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1453 题意: 中文题诶~ 思路: 因为最后一个球总是在编号比 ...
- 【BZOJ】2111: [ZJOI2010]Perm 排列计数 计数DP+排列组合+lucas
[题目]BZOJ 2111 [题意]求有多少1~n的排列,满足\(A_i>A_{\frac{i}{2}}\),输出对p取模的结果.\(n \leq 10^6,p \leq 10^9\),p是素数 ...
- 【BZOJ】4559: [JLoi2016]成绩比较 计数DP+排列组合+拉格朗日插值
[题意]n位同学(其中一位是B神),m门必修课,每门必修课的分数是[1,Ui].B神碾压了k位同学(所有课分数<=B神),且第x门课有rx-1位同学的分数高于B神,求满足条件的分数情况数.当有一 ...
随机推荐
- PHP 函数 ignore_user_abort()
ignore_user_abort 设置与客户机断开是否会终止脚本的执行. 本函数返回 user-abort 设置的之前的值(一个布尔值). int ignore_user_abort ([ st ...
- Python 调用multiprocessing模块下面的Process类方法(实现服务器、客户端并发)-UDP协议
#基于UDP协议的multiprocessing自定义通信 服务端: from multiprocessing import Process import socket def task(server ...
- [转]linux多命令的顺序执行
当我们需要一次执行多个命令的时候,命令之间需要用连接符连接,不同的连接符有不同的效果. (1) ; 分号,没有任何逻辑关系的连接符.当多个命令用分号连接时,各命令之间的执行成功与否彼此没有任何影响,都 ...
- ora-08104 该索引对象 159639 正在被联机建立或重建
SSH远程连接数据库创建索引,网络中断后,删除索引信息报ora-08104 解决方法: 使用ONLINE_INDEX_CLEAN清除索引痕迹 在sys用户下执行 SQL> conn /as sy ...
- iOS学习笔记01-APP相关
AppDelegate对象方法 # 程序第一次启动后才会执行 - (BOOL)application:(UIApplication *)application didFinishLaunchingWi ...
- TroubleShoot: SharePoint 2013: ExecuteOrDelayUntilScriptLoaded 页面发布后不执行的问题
SharePoint 2010 中的ExecuteOrDelayUntilScriptLoaded,在2013 中使用时没有效果的问题. Example: SharePoint 2013 Code: ...
- Introduction to the WinPcap Networking Libraries
Introduction to the WinPcap Networking Libraries use wire shark or fiddler
- 开始学习es6(一) 搭建个es6的开发环境
1.开始学习es6 如果想在浏览器跑es6 需要给es6个环境 因为一直用vue-cli全家桶 这样虽然方便 但如果用es6需要跑起个vue全家桶 于是想到可以用gulp搭建个开发环境 首先需要1. ...
- 【MFC】error RC2108: expected numerical dialog constant(转)
原文转自 http://blog.csdn.net/renyhui/article/details/23120469 [解决方案]在控件ID后面添加 "Static", SS_BI ...
- 快充 IC BQ25896 的 ICO (input current optimizer)
ICO (input current optimizer) 手機接上 adapter 後, 手機裡的 charger IC bq25896 開始向 adapter 抽取 current 供給 batt ...