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 ...
随机推荐
- C,C++,JAVA char,各占字节数
char在C和C+中占一个字节 Java中无论是汉字还是英文字母都是用Unicode编码来表示的,一个Unicode码是16位,每字节是8位,所以一个Unicode码占两字节 /** * The nu ...
- Provider Communication with Apple Push Notification Service
This chapter describes the interfaces that providers use for communication with Apple Push Notificat ...
- 《ArcGIS Engine+C#实例开发教程》第八讲 属性数据表的查询显示
原文:<ArcGIS Engine+C#实例开发教程>第八讲 属性数据表的查询显示 第一讲 桌面GIS应用程序框架的建立 第二讲 菜单的添加及其实现 第三讲 MapControl与Page ...
- 学习kernel编程的建议
我把我学习kernel编程的过程介绍给大家,希望大家有个参考. 学习kernel编程需要阅读大量的kernel方面的书籍,在此我列举一下我读过的kernel书籍(按时间先后顺序),并给一些建议. 1. ...
- freshStartTail 第一次启动时 抛弃旧的日志
freshStartTail [on/off] (requires v8.18.0+) Default: off This is used to tell rsyslog to seek to the ...
- WCF - WAS Hosting
WCF - WAS Hosting To understand the concept of WAS hosting, we need to comprehend how a system is co ...
- bzoj2763
首先是稀疏图,不难想到dij+heap 观察题目可以知道,0<=k<=10; 所以比较裸的想法就是,d[i,j]表示已经免费了i条线路后到达j的最短路 容易得到 d[i,j]:=min(d ...
- SCOI2005互不侵犯King
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1499 Solved: 872[Submit][S ...
- $apply() $digest()
理解Angular中的$apply()以及$digest() <!DOCTYPE html> <html> <head> <meta charset=&quo ...
- 【转】增加eclipse的运行内存 -- 不错!!
原文网址:http://blog.csdn.net/qa962839575/article/details/43605241 今天在eclipse 中测试把文档转换为图片的时候,报出了下面的错误: J ...