题目大意:
  一个游戏关卡有$n(n\le50)$个任务,若在$m$秒内按顺序完成所有任务则算作通过当前关卡。每个关卡有三个属性$a_i,b_i,p_i(1\le a_i<b_i\le100,80\le p_i\le99)$,表示有$p_i\%$的概率用$a_i$秒完成任务$i$,有$1-p_i\%$的概率用$b_i$秒完成任务$i$。每完成一个任务后可以选择继续下一个任务或重新开始当前关卡。问通过当前关卡的期望时间。

思路:
  二分答案$k$,并用期望DP进行检验。
  用$f[i][j]$表示从第$n$个任务到第$i$个任务,倒计时还剩$j$秒,总时间的期望。
  $f[i][j]=(f[i+1][j+a_i]+a_i)p_i+(f[i+1][j+b_i]+b_i)(1-p_i)$。
  若$f[i][j]>k$,重新开始当前关卡更优,令$f[i][j]=k$。
  则状态转移方程为$f[i][j]=\min((f[i+1][j+a_i]+a_i)p_i+(f[i+1][j+b_i]+b_i)(1-p_i),k)$。
  若$f[0][0]<k$,则期望不大于$k$。

 #include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=,M=;
const double eps=1e-;
int n,m,a[N],b[N],p[N];
double f[N][M];
inline bool check(const double &k) {
for(register int i=n-;~i;i--) {
for(register int j=m+;j<M;j++) f[i+][j]=k;
for(register int j=;j<=m;j++) {
f[i][j]=std::min((f[i+][j+a[i]]+a[i])*p[i]/+(f[i+][j+b[i]]+b[i])*(-p[i])/,k);
}
}
return f[][]<k;
}
int main() {
n=getint(),m=getint();
for(register int i=;i<n;i++) {
a[i]=getint(),b[i]=getint(),p[i]=getint();
}
double l=,r=1e9;
while(r-l>eps) {
const double mid=(l+r)/;
(check(mid)?r:l)=mid;
}
printf("%.10f\n",r);
return ;
}

[CF865C]Gotta Go Fast的更多相关文章

  1. 【CF865C】Gotta Go Fast 二分+期望DP

    [CF865C]Gotta Go Fast 题意:有n个关卡需要依次通过,第i关有pi的概率要花ai时间通过,有1-pi的概率要花bi时间通过,你的目标是花费不超过m的时间通关,每一关开始时你都可以选 ...

  2. [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 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案

    You're trying to set the record on your favorite video game. The game consists of N levels, which mu ...

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

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

  5. #3 Codeforces-865C Gotta Go Fast(期望dp)

    题意:一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每通过一关后可以选择继续下一关或者时间清0并从第一关开始,先要求通过所有关卡的时间和不 ...

  6. 项目必备!永无 bug 注释

    佛祖保佑 永无bug 代码注释 // // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`-- ...

  7. 佛祖保佑永无BUG代码注释

    // // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`---'\___ // .' \\| ...

  8. 佛祖保佑 永无bug 代码注释

    // // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`---'\___ // .' \\| ...

  9. codeforces865C

    Gotta Go Fast CodeForces - 865C You're trying to set the record on your favorite video game. The gam ...

随机推荐

  1. URAL1277 Cops and Thieves(最小割)

    Cops and Thieves Description: The Galaxy Police (Galaxpol) found out that a notorious gang of thieve ...

  2. bzoj 4237 稻草人 CDQ

    稻草人 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 1433  Solved: 626[Submit][Status][Discuss] Descr ...

  3. 栈与递归的实现(Hanoi塔问题等等)

    函数中有直接或间接地调用自身函数的语句,这样的函数称为递归函数.递归函数用 得好,可简化编程工作.但函数自己调用自己,有可能造成死循环.为了避免死循环,要 做到两点: (1) 降阶.递归函数虽然调用自 ...

  4. 使用state模块部署lamp架构

    install_httpd: pkg.installed: - name: httpd httpd_running: service.running: - name: httpd - enable: ...

  5. noip2016 普及组

    T1 买铅笔 题目传送门 #include<cstdio> #include<cstring> #include<algorithm> using namespac ...

  6. vue this.$router.push 页面不刷新

    解决办法: 使用 watch,观察路由,发生变化重新获取数据 <script> export default { data() { return { data: {} } }, metho ...

  7. Windows XP SP1 Privilege Escalation

    MS05-018 MS05-018 Works for Windows 2K SP3/4 | Windows XP SP1/2 Download ms05-018.exe: https://githu ...

  8. Ubuntu Touch环境搭建

    最近搞了一下Nexus 5的MultiRom Manger,体验了一把Ubuntu Touch和Android L,总体感觉还不错,不过Android L的NFC驱动还有问题,Ubuntu Touch ...

  9. python基础===pip安装模块失败

    此情况只用于网络不畅的安装模块背景: 总出现红色的 Could not find a version that satisfies the requirement pymongo(from versi ...

  10. Opencv第三章

    2. 下面这个练习是帮助掌握矩阵类型.创造一个三通道二维矩阵,字节类型,大小为100×100,并设置所有数值为0. a. 在矩阵中使用void cvCircle(CvArr* img, CvPoint ...