一直在考虑, 每一段的贡献, 没想到这个东西能直接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 (看题解)的更多相关文章

  1. Codeforces 596D Wilbur and Trees

    http://codeforces.com/contest/596/problem/D 题目大意: 有n棵树排成一排,高度都为h. 主人公要去砍树,每次等概率地随机选择没倒的树中最左边的树或者最右边的 ...

  2. Codeforces 442D Adam and Tree dp (看题解)

    Adam and Tree 感觉非常巧妙的一题.. 如果对于一个已经建立完成的树, 那么我们可以用dp[ i ]表示染完 i 这棵子树, 并给从fa[ i ] -> i的条边也染色的最少颜色数. ...

  3. Codeforces 1101F Trucks and Cities dp (看题解)

    Trucks and Cities 一个很显然的做法就是二分然后对于每个车贪心取check, 这肯定会TLE, 感觉会给人一种贪心去写的误导... 感觉有这个误导之后很难往dp那个方向靠.. dp[ ...

  4. Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)

    New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...

  5. Codeforces 865C Gotta Go Fast 二分 + 期望dp (看题解)

    第一次看到这种骚东西, 期望还能二分的啊??? 因为存在重置的操作, 所以我们再dp的过程中有环存在. 为了消除环的影响, 我们二分dp[ 0 ][ 0 ]的值, 与通过dp得出的dp[ 0 ][ 0 ...

  6. Codeforces 513E2 Subarray Cuts dp (看题解)

    我们肯定要一大一小间隔开来所以 把式子拆出来就是类似这样的形式 s1 - 2 * s2 + 2 * s3 + ...... + sn 然后把状态开成四个, 分别表示在顶部, 在底部, 在顶部到底部的中 ...

  7. Codeforces 983C Elevator dp (看题解)

    Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...

  8. Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)

    Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...

  9. Codeforces 498B Name That Tune 概率dp (看题解)

    Name That Tune 刚开始我用前缀积优化dp, 精度炸炸的. 我们可以用f[ i ][ j ] 来推出f[ i ][ j + 1 ], 记得加加减减仔细一些... #include<b ...

随机推荐

  1. Linux系统下安装pycharm

    在 linux下打开浏览器,搜索pycharm,点击download. 下载好的文件的名称可能是 ‘pycharm-professional-2018.3.5.tar.gz’. 打开终端界面,输入命令 ...

  2. Ex3_28 在2SAT问题中,给定一个字句的集合..._第十二次作业

    参考答案 ----------------------------------------------------------------------------------------------- ...

  3. django的内置信号

    Model singnalspre_init 在model执行构造方法之前自动触发post_init django的model在执行构造方法之后,自动触发pre_save django的对象保存之前, ...

  4. jqgrid获取数据条数

    function getResult() {//获取结果结合的函数,可以通过此函数获取查询后匹配的所有数据行.         var o = jQuery("#jqgrid"); ...

  5. python时间日期格式化和反格式化

    strftime()和strptime()行为 date,datetime和time对象都支持一种 strftime(format)方法,以创建一个表示显式格式字符串控制下的时间的字符串.从广义上讲, ...

  6. 洛谷P4841 城市规划 [生成函数,NTT]

    传送门 题意简述:求\(n​\)个点的简单无向连通图的数量\(\mod \;1004535809​\),\(n \leq 130000​\) 经典好题呀!这里介绍两种做法:多项式求逆.多项式求对数 先 ...

  7. ios中input获取焦点时的问题

    1.获取焦点时,input会变大 解决办法是:font-size设置为32px以上 还有就是要在header里面加这一行代码:<meta name="viewport" co ...

  8. swift 实践- 07 -- UISwitch 开关

    import UIKit class ViewController: UIViewController { var uiswitch: UISwitch? override func viewDidL ...

  9. STM32应用实例十四:利用光敏二极管实现光度测量

    最近我们在开发臭氧发生器时,需要监测生成的臭氧的浓度,于是想到使用光度计来测量.因为不同浓度的臭氧对管的吸收作用是不相同的,于是检测光照强度的变化就可以得到相应的浓度数据. 1.硬件设计 此次光照度检 ...

  10. Nginx(./configure --help)

    # ./configure --help --help print this message --prefix=PATH set installation prefix --sbin-path=PAT ...