URAL 1994 The Emperor's plan
期望$dp$。
$dp[i][j]$表示第$1$种人有$i$个,第$2$种人有$j$个的情况下,到达目标状态的期望值。初始化$dp[i][0]=i$。
枚举一下这个状态死多少人,取个$max$,最后$dp[n-k][k]$就是答案。
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define ms(x,y) memset(x,y,sizeof(x))
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define per(i,j,k) for(int i=j;i>=k;i--)
#define loop(i,j,k) for (int i=j;i!=-1;i=k[i])
#define inone(x) scanf("%d",&x)
#define intwo(x,y) scanf("%d%d",&x,&y)
#define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p)
#define lson x<<1,l,mid
#define rson x<<1|1,mid+1,r
#define mp(i,j) make_pair(i,j)
#define ft first
#define sd second
typedef long long LL;
typedef pair<int, int> pii;
const int low(int x) { return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + ;
const int N = 1e6 + ;
const int M = 1e4 + ;
const double eps = 1e-; double dp[][];
double c[][]; int n,k; void init()
{
c[][]=;
for(int i=;i<=;i++)
{
c[i][]=;
c[i][i]=;
for(int j=;j<=;j++)
{
c[i][j] = c[i-][j] + c[i-][j-];
}
}
} int main()
{
init();
while(~scanf("%d%d",&n,&k))
{
memset(dp,,sizeof dp);
for(int i=;i<=n-k;i++) dp[i][]=1.0*i; for(int i=;i<=n-k;i++)
{
for(int j=;j<=k;j++)
{
if(j==) continue; int pn = i-j;
int pk = j; for(int p=;p<=pn+pk;p++)
{
double sum=;
for(int L=;L<=pn;L++)
{
int R = p-L;
if(R<) break;
if(pk<R) continue;
sum=sum+dp[pn-L][pk-R]*c[pn][L]*c[pk][R]/c[pn+pk][p];
}
dp[i][j]=max(sum,dp[i][j]);
}
}
} printf("%.10f\n",dp[n-k][k]); }
return ;
}
URAL 1994 The Emperor's plan的更多相关文章
- URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...
- ural 1144. The Emperor's Riddle
1144. The Emperor's Riddle Time limit: 1.0 secondMemory limit: 4 MB Background In the olden times th ...
- 2013-2014 ACM-ICPC, NEERC, Eastern Subregional Contest PART (8/10)
$$2013-2014\ ACM-ICPC,\ NEERC,\ Eastern\ Subregional\ Contest$$ \(A.Podracing\) 首先枚举各个折现上的点,找出最小宽度,然 ...
- Timusoj 1982. Electrification Plan
http://acm.timus.ru/problem.aspx?space=1&num=1982 1982. Electrification Plan Time limit: 0.5 sec ...
- ural 2062 Ambitious Experiment
2062. Ambitious Experiment Time limit: 3.0 secondMemory limit: 128 MB During several decades, scient ...
- ural 1272. Non-Yekaterinburg Subway
1272. Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to co ...
- bzoj 1814 Ural 1519 Formula 1 插头DP
1814: Ural 1519 Formula 1 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 942 Solved: 356[Submit][Sta ...
- 测试计划(Test Plan)
测试计划(Test Plan) 版权声明:本文为博主原创文章,未经博主允许不得转载. 测试计划的概念: 测试计划是一个文档,描述了进行测试的测试范围,测试策略和方法,测试资源和进度.是对整个测试活动进 ...
- SQL Tuning 基础概述02 - Explain plan的使用
1.explain plan的使用 SQL> explain plan for delete from t_jingyu; Explained. SQL> select * from ta ...
随机推荐
- [LeetCode] 23. Merge k Sorted Lists ☆☆
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 解 ...
- Codeforces 807 A Is it rated?
http://codeforces.com/problemset/problem/807/A A. Is it rated? time limit per test 2 se ...
- 2015/9/28 Python基础(19):类的定制和私有性
用特殊方法定制类前面我们讲了方法的两个重要方面:首先,方法必须在调用前被绑定(到它们相应类的某个实例中):其次,有两个特殊方法可以分别作为构造器和解构器的功能,分别名为__init__()和__del ...
- Spring Boot 使用IntelliJ IDEA创建一个web开发实例(四)
多环境配置 1. 在springBoot多环境配置文件名需要满足application-{profile}.properties的格式,其中{profile}对应你的环境标识,例如: (1)appli ...
- MongoDB-3.4集群搭建:分片
概念 集群拥有三个节点: 分片(sharding),分发路由(query routers)和配置服务器 (config server) Shard 分片是存储了一个集合部分数据的MongoDB实例,每 ...
- 51nod 1120 机器人走方格 V3
N * N的方格,从左上到右下画一条线.一个机器人从左上走到右下,只能向右或向下走. 并要求只能在这条线的上面或下面走,不能穿越这条线,有多少种不同的走法? 由于方法数量可能很大,只需要输出Mod 1 ...
- 【BZOJ】3091: 城市旅行 Link-Cut Tree
[题意]参考PoPoQQQ. 给定一棵树,每个点有一个点权,提供四种操作: 1.删除两点之间的连边 不存在边则无视 2.在两点之前连接一条边 两点已经联通则无视 3.在两点之间的路径上所有点的点权加上 ...
- sylk文件
症状:excel表出现提示:sylk文件...导致excel表不可读取 原因:文件内容有“ ID ” 字段,估计是固定的识别“ID”或“ID_XXXX” 修改方法:将ID中的任意字母换成小写即可 转载 ...
- 简单响应式Bootstrap框架中文官网页面模板
链接:http://pan.baidu.com/s/1o7MQ6RC 密码:kee5
- 简单实现JS上传图片预览功能
HTML代码 <div class="upload"> <input type="button" class="btn" ...