Gotta Go Fast

CodeForces - 865C

You're trying to set the record on your favorite video game. The game consists of Nlevels, 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 8
2 8 81
Output
3.14
Input
2 30
20 30 80
3 9 85
Output
31.4
Input
4 319
63 79 89
79 97 91
75 87 88
75 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.

sol:

dp[i][j]表示当前为第i关,已用时j,从当前开始通关的用时期望
tmp表示从头开始通关的用时期望
设当前状态为(i,j):
①如果在挑战第i关前选择重新开始游戏,则通关的期望值tmp
②如果通过第i关用时为a[i],则继续进行游戏并通关的期望值为(dp[i+1][j+a[i]]+a[i])*p[i]
③如果通过第i关用时为b[i],则继续进行游戏并通关的期望值为(dp[i+1][j+b[i]]+b[i])*(1-p[i])

/*
dp[i][j]表示当前为第i关,已用时j,从当前开始通关的用时期望
tmp表示从头开始通关的用时期望
设当前状态为(i,j):
①如果在挑战第i关前选择重新开始游戏,则通关的期望值tmp
②如果通过第i关用时为a[i],则继续进行游戏并通关的期望值为(dp[i+1][j+a[i]]+a[i])*p[i]
③如果通过第i关用时为b[i],则继续进行游戏并通关的期望值为(dp[i+1][j+b[i]]+b[i])*(1-p[i])
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=; bool f=; char ch=' ';
while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
while(isdigit(ch)) {s=(s<<)+(s<<)+(ch^); ch=getchar();}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<) {putchar('-'); x=-x;}
if(x<) {putchar(x+''); return;}
write(x/); putchar((x%)+'');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=,M=;
const double eps=1e-;
int n,m,a[N],b[N],p[N];
double dp[N][M];
inline bool chk(double tmp)
{
int i,j;
for(i=n;i>=;i--)
{
for(j=m+;j<M;j++) dp[i+][j]=tmp; //重来
for(j=;j<=m;j++)
{
double t1=(double)(dp[i+][j+a[i]]+a[i])*p[i]/;
double t2=(double)(dp[i+][j+b[i]]+b[i])*(-p[i])/;
dp[i][j]=min(t1+t2,tmp);
}
}
return dp[][]<tmp;
}
int main()
{
freopen("data.in","r",stdin);
int i;
R(n); R(m);
for(i=;i<=n;i++)
{
R(a[i]); R(b[i]); R(p[i]);
}
double l=0.00,r=1e10,mid;
for(i=;i<=;i++)
{
mid=(l+r)*0.50;
if(chk(mid)) r=mid;
else l=mid;
}
printf("%.12lf\n",l);
return ;
}
/*
input
4 319
63 79 89
79 97 91
75 87 88
75 90 83
output
314.159265358
*/

codeforces865C的更多相关文章

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

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

随机推荐

  1. 怎样查看Redis的版本号

    Q: 怎样查看Redis版本 A: 下面两条命令都可以查看redis 版本: redis-server --version redis-server -v

  2. MQTT协议探究(一)

    1 准备阶段 MQTT客户端:https://www.cnblogs.com/linzhanfly/p/9923577.html WireShark MQTT服务器(iot.eclipse.org) ...

  3. Lua虚拟机中的数据结构与栈

    Lua虚拟机中的数据结构与栈 来源 https://blog.csdn.net/zry112233/article/details/80828327 由上一篇文章可知解释器分析Lua文件之后生成Pro ...

  4. js组合继承

    //组合继承指的是将原型链和借用构造函数(call.apply)的技术组合到一起,从而发挥二者之长的一种继承模式,//其背后的思路就是使用原型链实现对原型属性和方法的继承://而通过借用构造函数来实现 ...

  5. 关于Mybatis的几件小事(二)

    一.MyBatis缓存机制 1.简介 Mybatis包含了一个非常强大的查询缓存的特性,它可以非常方便地配置和定制. 缓存key极大提高查询效率 MyBatis系统中默认定义了两次缓存 默认情况下,只 ...

  6. LeetCode:1179.重新格式化部门表

    题目链接:https://leetcode-cn.com/problems/reformat-department-table/ 题目 部门表 Department: +--------------- ...

  7. 【转】axios用post提交的数据格式

    本文链接:https://blog.csdn.net/wopelo/article/details/78783442vue框架推荐使用axios来发送ajax请求,之前我还写过一篇博客来讲解如何在vu ...

  8. 给datagrid一列中的数据加上单位

    { field:'computeRate', title:'完成百分比', width:100, align:'center', halign:'center', sortable:true, for ...

  9. springboot集成websocket的两种实现方式

    WebSocket跟常规的http协议的区别和优缺点这里大概描述一下 一.websocket与http http协议是用在应用层的协议,他是基于tcp协议的,http协议建立链接也必须要有三次握手才能 ...

  10. 织梦后台系统设置在PHP5.4环境中不能保存中文参数的解决方法

    在没用PHP5.4的环境做Dede后台的时候,织梦58一直没有遇到这个问题,昨天上传一个新的模版到空间去测试发现后台的系统基本参数设置中所有的中文内容都无法保存,关于这个问题,其实以前也听说过,知识一 ...