URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
URAL 1994 The Emperor's plan 求组合数 大数用log
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include <stack>
#define REP(i, n) for(int i=0; i<n; i++)
#define PB push_back
#define LL long long
#define CLR(a, b) memset(a, b, sizeof(a))
using namespace std; const int maxn = 210; double LOG[210];
void pre()
{
for (int i = 1; i < 210; i++)
LOG[i] = LOG[i - 1] + log(i * 1.0);
}
double CN(int a, int b)
{
return LOG[b] - LOG[a] - LOG[b - a];
}
double PN(int a, int b, int c, int d)
{
return exp( CN(c, a) + CN(d, b) - CN(c + d, a + b) );
} double dp[210][21];
bool vis[210][21]; double dpf(int n, int k)
{
if (k == 0) return n;
if (n <= k) return 0;
if (vis[n][k]) return dp[n][k];
vis[n][k] = 1;
double &ans = dp[n][k];
ans = 0;
n -= k; int sum = n + k;
for (int i = 1; i < sum; i++)
{
double now = 0;
int x = min(i, k);
for (int j = 0; j <= x; j++)
now += dpf(n - (i - j), k - j) * PN(n, k, i - j, j);
ans = max(ans, now);
}
return ans;
} /***求组合数,无效值为0
const int maxcn = 20;
int cn[maxcn][maxcn];
int init()
{
for (int i = 1; i < maxcn; i++)
{
cn[i][0] = cn[i][i] = 1;
for (int j = 1; j < i; j++)
cn[i][j] = cn[i - 1][j - 1] + cn[i - 1][j];
}
}
*/ int main()
{
int n, k;
pre();
scanf("%d%d", &n, &k);
printf("%.10lf\n", dpf(n - k, k));
}
URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理的更多相关文章
- URAL 1994 The Emperor's plan
期望$dp$. $dp[i][j]$表示第$1$种人有$i$个,第$2$种人有$j$个的情况下,到达目标状态的期望值.初始化$dp[i][0]=i$. 枚举一下这个状态死多少人,取个$max$,最后$ ...
- lucas求组合数C(n,k)%p
Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...
- 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个数中 ...
- HDU 5698——瞬间移动——————【逆元求组合数】
瞬间移动 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】
任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...
随机推荐
- Excel技巧收录
帮老婆弄Excel,自己也把学到的东西记录下,免得以后被问到又给忘了 数据透视,需先在数据透视区域加上表头,如公司名称.销量等,Excel数据透视默认将选择区域的第一行作为表头 VLOOKUP,VLO ...
- Centos 6.4上面用Shell脚本一键安装vsftpd
Centos 6.4上面用Shell脚本一键安装vsftpd install.sh #!/bin/bash if [ `uname -m` == "x86_64" ];then m ...
- Bengio最新博文:深度学习展望
Bengio最新博文:深度学习展望 人类一直梦想着创造有智能的机器.早在第一台可编程计算机问世前100多年,发明家就对如何能让由连杆和齿轮组成的设备也变得更加智能这一命题充满好奇.后来,20世纪40年 ...
- sublime text 2 前端编码神器-快捷键与使用技巧介绍
介绍网址:http://www.xuanfengge.com/sublime-text-2-artifact.html
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-004-Pizza例子的用户流程(flowExecutionKey、_eventId_phoneEntered、flowExecutionUrl )
一. 1. 2. 3.customer-flow.xml 自己定义customer,最后output <?xml version="1.0" encoding="U ...
- MySQL 性能调优的10个方法
Mysql的优化方面,一般我们很少去考虑它,即使想到优化一般也更多是程序级别的,比如不要写过于消耗资源的SQL语句,但是除此以外,在整个系统上其实仍然有很多可以优化的地方. 1. 选择合适的存储引擎: ...
- OSFM Tables
OSFM - Oracle Shop Floor Management 1. (N) Shop Floor Manager > Lot Based Jobs (B: New) Status: U ...
- c#调用c++动态库的一些理解
调用c++动态库一般我们这样写 [DllImport("UCamer.dll", CallingConvention = CallingConvention.Winapi)] ...
- POJ_1064_Cable_master_(二分,假定一个解并判断是否可行)
描述 http://poj.org/problem?id=1064 有n条绳子,长度分别为l[i].如果从它们中切割出k条长度相同的绳子的话,这k条绳子每条最长能有多少? Cable master T ...
- VMwareWorkstation10安装OS_X_Mavericks10.9.2图文详细教程
一.VMware的环境配置... 1.1安装VMware的MAC OS补丁... 1.2建立虚拟机... 二.OS_X_Mavericks的安装及安装驱动... ...