You're trying to set the record on your favorite video game. The game consists of N levels, which must be completed sequentially in order to beat the game. You usually complete each level as fast as possible, but sometimes finish a level slower. Specifically, you will complete the i-th level in either Fi seconds or Si seconds, where Fi < Si, and there's a Pi percent chance of completing it in Fi seconds. After completing a level, you may decide to either continue the game and play the next level, or reset the game and start again from the first level. Both the decision and the action are instant.

Your goal is to complete all the levels sequentially in at most R total seconds. You want to minimize the expected amount of time playing before achieving that goal. If you continue and reset optimally, how much total time can you expect to spend playing?

Input

The first line of input contains integers N and R , the number of levels and number of seconds you want to complete the game in, respectively. N lines follow. The ith such line contains integers Fi, Si, Pi (1 ≤ Fi < Si ≤ 100, 80 ≤ Pi ≤ 99), the fast time for level i, the slow time for level i, and the probability (as a percentage) of completing level i with the fast time.

Output

Print the total expected time. Your answer must be correct within an absolute or relative error of 10 - 9.

Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if .

Examples
input
1 82 8 81
output
3.14
input
2 3020 30 803 9 85
output
31.4
input
4 31963 79 8979 97 9175 87 8875 90 83
output
314.159265358
Note

In the first example, you never need to reset. There's an 81% chance of completing the level in 2 seconds and a 19% chance of needing 8 seconds, both of which are within the goal time. The expected time is 0.81·2 + 0.19·8 = 3.14.

In the second example, you should reset after the first level if you complete it slowly. On average it will take 0.25 slow attempts before your first fast attempt. Then it doesn't matter whether you complete the second level fast or slow. The expected time is 0.25·30 + 20 + 0.85·3 + 0.15·9 = 31.4.


  题目大意 一个人打游戏,需要不超过$R$秒通过$n$关,第$i$关有$P_{i}$的概率用$F_{i}$秒通过,$\left(1 - P_{i}\right)$的概率用$S_{i}$通过($F_{i} < S_{i}$),通过每一关可以选择重置游戏,然后从头开始,或者去打下一关。问不超过$R$秒通过所有关卡的期望耗时。

  转移是显然的。(如果这个都不会,请自定百度“概率dp入门题”)

  然后发现转移有环,还要做决策?

  然后列方程吧。。开心地发现不会解。

  可惜这里是信息学竞赛,不是数学竞赛。由于转移都需要 dp[][] 但是开始不知道它,所以考虑二分它,然后和推出来的 dp[][] 作比较。

  经过各种瞎猜和乱搞,可以发现一个神奇的事情

  然后就可根据它来确定一次check后,二分的范围。

  另外,由于坑人的精度问题,所以最好不要写while (l + eps < r) ,总之我这么写各种因为精度问题的TLE来了。

Code

 /**
  * Codeforces
  * Problem#866C
  * Accepted
  * Time: 62ms
  * Memory: 4316k
  */
 #include <bits/stdc++.h>
 using namespace std;
 typedef bool boolean;

 ;
 ;

 int n, R;
 int *fs, *ss;
 double *ps;

 inline void init() {
     scanf("%d%d", &n, &R);
     fs = )];
     ss = )];
     ps = )];
     ; i <= n; i++) {
         scanf("%d%d", fs + i, ss + i);
         cin >> ps[i];
         ps[i] *= 0.01;
     }
 }

 boolean vis[][];
 ][];

 double dfs(int d, int t, double &mid) {
     );
     if(vis[d][t])    return f[d][t];
     vis[d][t] = true;
     f[d][t] = (dfs(d + , t + fs[d + ], mid) + fs[d + ]) * ps[d + ] + (dfs(d + , t + ss[d + ], mid) + ss[d + ]) * ( - ps[d + ]);
     if(mid < f[d][t])    f[d][t] = mid;
     return f[d][t];
 }

 double dp(double mid) {
     memset(vis, false, sizeof(vis));
     , , mid);
 }

 inline void solve() {
     , r = 1e9;
     ; i < binary_lim; i++) {
         ;
         if(dp(mid) < mid)    r = mid;
         else    l = mid;
     }
     printf("%.9lf", l);
 }

 int main() {
     init();
     solve();
     ;
 }

Codeforces 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案的更多相关文章

  1. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

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

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

  3. bzoj 4318 OSU! - 动态规划 - 概率与期望

    Description osu 是一款群众喜闻乐见的休闲软件.  我们可以把osu的规则简化与改编成以下的样子:  一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1 ...

  4. bzoj 4008 亚瑟王 - 动态规划 - 概率与期望

    Description 小 K 不慎被 LL 邪教洗脑了,洗脑程度深到他甚至想要从亚瑟王邪教中脱坑. 他决定,在脱坑之前,最后再来打一盘亚瑟王.既然是最后一战,就一定要打得漂 亮.众所周知,亚瑟王是一 ...

  5. bzoj 1419 Red is good - 动态规划 - 概率与期望

    Description 桌面上有R张红牌和B张黑牌,随机打乱顺序后放在桌面上,开始一张一张地翻牌,翻到红牌得到1美元,黑牌则付出1美元.可以随时停止翻牌,在最优策略下平均能得到多少钱. Input 一 ...

  6. Codeforces Round #202 (Div. 1) A. Mafia 推公式 + 二分答案

    http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory limit p ...

  7. Codeforces Round #402 (Div. 2) D. String Game(二分答案水题)

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  8. Codeforces Round #402 (Div. 2) D题 【字符串二分答案+暴力】

    D. String Game Little Nastya has a hobby, she likes to remove some letters from word, to obtain anot ...

  9. Educational Codeforces Round 80 (Rated for Div. 2)D(二分答案,状压检验)

    这题1<<M为255,可以logN二分答案后,N*M扫一遍表把N行数据转化为一个小于等于255的数字,再255^2检验答案(比扫一遍表复杂度低),复杂度约为N*M*logN #define ...

随机推荐

  1. shell基础:环境变量

    子shell是在父shell中打开的shell. 使用pstree查看进程树. $调用环境变量 set查看所有变量内容, env查询环境变量 只是临时改变

  2. linux df查看硬盘使用量 du查看文件所占大小

    df 常用来查看磁盘的占用情况. du 常用来查看文件夹的大小等. Linux命令: df  [-ahikHTm]  [目录或者文件夹] 参数: -h : 以交较易识别的方式展示使用量  111100 ...

  3. MyBatis基础入门《七》查询参数传入对象

    MyBatis基础入门<七>查询参数传入对象 描述: 在执行查询语句的时候,传入的参数是一个对象,依据对象的属性,进行检索数据.此时,书写SQL语句中的条件时,其参数需要和对象中的属性保持 ...

  4. NHibernate初学者指南系列文章导航

    NHibernate初学者指南系列文章导航   前面的话 经过三个多周的时间,终于将这个系列完成了,谢谢大家的关注和支持,有很多不足之处还望大家包涵. 本系列参考的书籍为NHibernate 3 Be ...

  5. 假如java类里的成员变量是自身的对象

    假如java类里的成员变量是自身的对象,则新建该类对象时内存中怎么分配空间,我感觉似乎死循环了. 不过我想的肯定是错的,因为很多类的成员变量是自身对象,并且绝对无错,举个例子: Class A{ pr ...

  6. 20155228 实验五 Android开发基础

    20155228 实验五 Android开发基础 实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.设计安全传输系统. 实验要求 1.没有Linux基础的同学建议先学习< ...

  7. GitHub 代码上传

    方法一 登录GitHub后,点击下面的图 New responsitory 按钮 或者点击绿色按钮 New repository,新建一个新建一个远程仓库(remote repository),点击后 ...

  8. PersistenceContext.properties()

    在做 Spring + SpringMVC + SpringData 时,单元测试 报这个错误: java.lang.NoSuchMethodError:javax.persistence.Persi ...

  9. 通过Hive将数据写入到ElasticSearch

    我在<使用Hive读取ElasticSearch中的数据>文章中介绍了如何使用Hive读取ElasticSearch中的数据,本文将接着上文继续介绍如何使用Hive将数据写入到Elasti ...

  10. Spring Batch 远程分区和远程分块的区别

    Partitioning is a master/slave step configuration that allows for partitions of data to be processed ...