Codeforces 596D Wilbur and Trees dp (看题解)
一直在考虑, 每一段的贡献, 没想到这个东西能直接dp。。因为所有的h都是一样的。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, h, x[N], lft[N], rgt[N];
double ans, p, pr, pl;
double f[N][N][][];
bool vis[N][N][][]; double dp(int i, int j, int u, int v) {
if(i > j) return ;
if(vis[i][j][u][v]) return f[i][j][u][v];
double& ans = f[i][j][u][v];
double tmp1 = , tmp2 = ;
if(!u) ans += 0.5 * pl * (dp(i + , j, , v) + min(h, x[i] - x[i - ])), tmp1 = min(h, x[i] - x[i - ]);
else ans += 0.5 * pl * (dp(i + , j, , v) + min(h, x[i] - x[i - ] - h)), tmp1 = min(h, x[i] - x[i - ] - h);
if(v) ans += 0.5 * pr * (dp(i, j - , u, ) + min(h, x[j + ] - x[j])), tmp2 = min(h, x[j + ] - x[j]);
else ans += 0.5 * pr * (dp(i, j - , u, ) + min(h, x[j + ] - h - x[j])), tmp2 = min(h, x[j + ] - h - x[j]);
int L = min(rgt[i], j), R = max(lft[j], i);
ans += 0.5 * pr * (dp(L + , j, , v) + x[L] - x[i] + (L != j ? h : tmp2));
ans += 0.5 * pl * (dp(i, R - , u, ) + x[j] - x[R] + (R != i ? h : tmp1));
vis[i][j][u][v] = true;
return ans;
} int main() {
scanf("%d%d%lf", &n, &h, &p);
pl = p, pr = - p;
for(int i = ; i <= n; i++) scanf("%d", &x[i]);
x[] = -inf, x[n + ] = inf;
sort(x + , x + + n);
lft[] = , rgt[n] = n;
for(int i = ; i <= n; i++)
lft[i] = x[i] - h < x[i - ] ? lft[i - ] : i;
for(int i = n - ; i >= ; i--)
rgt[i] = x[i] + h > x[i + ] ? rgt[i + ] : i;
printf("%.10f\n", dp(, n, , ));
return ;
} /*
*/
Codeforces 596D Wilbur and Trees dp (看题解)的更多相关文章
- Codeforces 596D Wilbur and Trees
http://codeforces.com/contest/596/problem/D 题目大意: 有n棵树排成一排,高度都为h. 主人公要去砍树,每次等概率地随机选择没倒的树中最左边的树或者最右边的 ...
- Codeforces 442D Adam and Tree dp (看题解)
Adam and Tree 感觉非常巧妙的一题.. 如果对于一个已经建立完成的树, 那么我们可以用dp[ i ]表示染完 i 这棵子树, 并给从fa[ i ] -> i的条边也染色的最少颜色数. ...
- Codeforces 1101F Trucks and Cities dp (看题解)
Trucks and Cities 一个很显然的做法就是二分然后对于每个车贪心取check, 这肯定会TLE, 感觉会给人一种贪心去写的误导... 感觉有这个误导之后很难往dp那个方向靠.. dp[ ...
- Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...
- Codeforces 865C Gotta Go Fast 二分 + 期望dp (看题解)
第一次看到这种骚东西, 期望还能二分的啊??? 因为存在重置的操作, 所以我们再dp的过程中有环存在. 为了消除环的影响, 我们二分dp[ 0 ][ 0 ]的值, 与通过dp得出的dp[ 0 ][ 0 ...
- Codeforces 513E2 Subarray Cuts dp (看题解)
我们肯定要一大一小间隔开来所以 把式子拆出来就是类似这样的形式 s1 - 2 * s2 + 2 * s3 + ...... + sn 然后把状态开成四个, 分别表示在顶部, 在底部, 在顶部到底部的中 ...
- Codeforces 983C Elevator dp (看题解)
Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...
- Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)
Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...
- Codeforces 498B Name That Tune 概率dp (看题解)
Name That Tune 刚开始我用前缀积优化dp, 精度炸炸的. 我们可以用f[ i ][ j ] 来推出f[ i ][ j + 1 ], 记得加加减减仔细一些... #include<b ...
随机推荐
- ubuntu server 14.04 上安装jdk1.8
ubuntu server 14.04 上安装jdk1.8 1.使用apt-get安装oracle-jdk安装oracle jdk sudo apt-get install python-softwa ...
- [转]Java微服务框架选型(Dubbo 和 Spring Cloud?)
转载于 http://www.cnblogs.com/xishuai/p/dubbo-and-spring-cloud.html 微服务(Microservices)是一种架构风格,一个大型复杂软件应 ...
- VUE 多页面配置(一)
1. 概述 1.1 说明 项目开发过程中会遇到需要多个主页展示情况,故在vue单页面的基础上进行配置多页面开发以满足此需求. 2. 实例 2.1 页面配置 2.1.1 默认首页 使用vue脚手架搭建后 ...
- JsRender 前端渲染模板基础学习
JsRender前端渲染模板 使用模板,可以预先自定义一些固定格式的HTML标签,在需要显示数据时,再传入真实数据组装并展示在Web页中:避免了在JS中通过“+”等手动分割.连接字符串的复杂过程:针对 ...
- Confluence 6 属性的一个活动
为了启用属性,使用上面描述的方法.针对所有的用户,属性每一个访问的页面,将会在你的应用服务器中进行记录,直到你对 Confluence 进行重启.请注意每次用户访问一个链接,一个单一的属性将会被打印出 ...
- Confluence 6 使用 Jira 管理用户
如果你已经使用了 Jira 来管理你的任务和 issue 的话,你可以选择将 Jira 和 Confluence 整合在一起,将用户管理集中到一个地方.你可以控制你 Jira 中的用户组是否具有使用 ...
- Confluence 6 导入模板的定义
模板是一个预先定义的页面,这个预先定义的页面可以在创建新页面的时候预先载入.模板能够给一个页面统一的样式或格式. 你可以在 Confluence 中创建你自己的模板,请查看页面 Create a Te ...
- Mybait缓存机制
MyBatis同大多数ORM框架一样,提供了一级缓存和二级缓存的支持. 一级缓存:其作用域为session范围内,当session执行flush或close方法后,一级缓存会被清空. 二级缓存:二级缓 ...
- spring boot 解决跨域访问
package com.newings.disaster.shelters.configuration; import org.springframework.context.annotation.B ...
- laravel 里面结合关联查询 的when()用法
Laravel 5.6 里面的when用法: $name = $request->get('name'); //活动标题 $start_time = $request->get('star ...