Codeforces 865C Gotta Go Fast 二分 + 期望dp (看题解)
第一次看到这种骚东西, 期望还能二分的啊???
因为存在重置的操作, 所以我们再dp的过程中有环存在。
为了消除环的影响, 我们二分dp[ 0 ][ 0 ]的值, 与通过dp得出的dp[ 0 ][ 0 ]的值进行比较。
这样看着好像很不合理, 但实际上比较这两个值, 你能推倒出当前二分的值合不合法。
#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 = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const double PI = acos(-); int n, R, F[N], S[N], up;
double P[N];
double dp[ + ][ * + ]; double dfs(int i, int j, double x) {
if(i == n) {
if(j <= R) return ;
else return x;
}
if(dp[i][j] + eps > ) return dp[i][j];
double T1 = P[i + ] * (dfs(i + , j + F[i + ], x) + F[i + ]) + ( - P[i + ]) * (dfs(i + , j + S[i + ], x) + S[i + ]);
dp[i][j] = min(T1, x);
return dp[i][j];
} bool check(double x) {
for(int i = ; i <= n; i++)
for(int j = ; j <= up; j++)
dp[i][j] = -;
if(dfs(, , x) < x) return true;
else return false;
}
int main() {
scanf("%d%d", &n, &R);
for(int i = ; i <= n; i++) {
scanf("%d%d%lf", &F[i], &S[i], &P[i]);
P[i] /= ;
up += S[i];
}
double low = n, high = 5e8;
for(int o = ; o <= ; o++) {
double mid = (low + high) / ;
if(check(mid)) high = mid;
else low = mid;
}
printf("%.12f\n", (low + high) / );
return ;
} /*
*/
Codeforces 865C Gotta Go Fast 二分 + 期望dp (看题解)的更多相关文章
- 【CF865C】Gotta Go Fast 二分+期望DP
[CF865C]Gotta Go Fast 题意:有n个关卡需要依次通过,第i关有pi的概率要花ai时间通过,有1-pi的概率要花bi时间通过,你的目标是花费不超过m的时间通关,每一关开始时你都可以选 ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- #3 Codeforces-865C Gotta Go Fast(期望dp)
题意:一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每通过一关后可以选择继续下一关或者时间清0并从第一关开始,先要求通过所有关卡的时间和不 ...
- Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...
- Codeforces 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案
You're trying to set the record on your favorite video game. The game consists of N levels, which mu ...
- Codeforces 830A. Office Keys (贪心二分 or DP)
原题链接:http://codeforces.com/contest/830/problem/A 题意:在一条数轴上分别有n个人和k把钥匙(n<=k),以及一个目的地,每个人要各自拿到一个钥匙后 ...
- Codeforces Round #548 (Div. 2) D 期望dp + 莫比乌斯反演
https://codeforces.com/contest/1139/problem/D 题意 每次从1,m中选一个数加入队列,假如队列的gcd==1停止,问队列长度的期望 题解 概率正着推,期望反 ...
- codeforces 352D - Jeff and Furik【期望dp】
首先恋人操作过一轮之后逆序对不会变多,所以设f[i]为把i个逆序对消掉的期望次数,f[i]=0.5f[i-2]+0.5f[i]+2,化简然后递推即可 #include<iostream> ...
- Codeforces 1101F Trucks and Cities dp (看题解)
Trucks and Cities 一个很显然的做法就是二分然后对于每个车贪心取check, 这肯定会TLE, 感觉会给人一种贪心去写的误导... 感觉有这个误导之后很难往dp那个方向靠.. dp[ ...
随机推荐
- 制作缩略图java工具类
import java.awt.Image; import java.awt.image.BufferedImage; import java.io.File; import java.io.File ...
- ASP.NET 验证码绘制
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- gcc/g++基本命令
gcc & g++现在是gnu中最主要和最流行的c & c++编译器 .g++是c++的命令,以.cpp为主,对于c语言后缀名一般为.c.这时候命令换做gcc即可.其实是无关紧要的.其 ...
- 前端 -----jQuery的位置信息
08-jQuery的位置信息 jQuery的位置信息跟JS的client系列.offset系列.scroll系列封装好的一些简便api. 一.宽度和高度 获取宽度 .width() 描述:为匹配的 ...
- Poco::Crypto--加解密_RSA
Poco::Crypto--加解密(RSA) 1.简单的加解密 Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(R ...
- WebRequest使用(车)
// 待请求的地址 string url = "http://www.cnblogs.com"; // 创建 WebRequest 对象,WebRequest 是抽象类,定义了请求 ...
- python之通过thread来实现多进程
代码如下: import threading, time class Test1(threading.Thread): def __init__(self, name): super().__init ...
- Android CTS Test
什么是CTS测试?了解这个问题前,我们先来搜索了解一遍“Google GMS 认证”.GMS全称为GoogleMobile Service,即谷歌移动服务.说白了GMS其实就是一系列谷歌的应用集合.谷 ...
- string标准C++中的的用法总结(转)
转自:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻 ...
- 【mysql】删除字段的最后一个字符
场景:在存入16进制id时,由于转换失误,得到的结果是0x1001L的格式,我希望转换为0x1001,去掉最后的L 指令: update tb_test set hexid=left(hexid, l ...