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. 学习GTK+ (1) ——编写helloworld

    环境 我使用的是新安装的manjaro 18.1 (kde版),安装新系统后后直接可以开始写代码,不需要安装各种调用的库等. 推荐一个网站,gnome开发者 https://developer.gno ...

  2. Windows一键设置环境变量(以设置java环境变量为例)

    右击以管理员方式运行 JDKSetting.bat   @echo off color 0a echo.------------------------------------ echo.TODO:设 ...

  3. 【IntelliJ IDEA】添加一个新的tomcat,tomcat启动无法访问欢迎页面,空白页,404

    ===================================第一部分,添加一个tomcat================================================== ...

  4. SQL连接(join)

    INNER JOIN:如果表中有至少一个匹配,则返回行 LEFT JOIN:即使右表中没有匹配,也从左表返回所有的行 RIGHT JOIN:即使左表中没有匹配,也从右表返回所有的行 FULL JOIN ...

  5. 无法删除登录名 '***',因为该用户当前正处于登录状态。 (Microsoft SQL Server,错误: 15434)

    问题描述: 当删除数据库用户时,有时会得到这样的提示: 无法删除登录名 '***',因为该用户当前正处于登录状态. (Microsoft SQL Server,错误: 15434) 解决办法: 1.首 ...

  6. TypeScript入门三:TypeScript函数类型

    TypeScript函数类型 TypeScript函数的参数 TypeScript函数的this与箭头函数 TypeScript函数重载 一.TypeScript函数类型 在上一篇博客中已经对声明Ty ...

  7. H5存储方式

    数据存储 var arr = [0, 1, 1, 1]; //存储,IE6~7 cookie 其他浏览器HTML5本地存储 if (window.localStorage) { localStorag ...

  8. 如何确定asp.net请求生命周期的当前处理事件

    1 首先在全局应用程序里面添加如下代码 using System; using System.Collections.Generic; using System.Linq; using System. ...

  9. FastJson学习:JSON格式字符串、JSON对象及JavaBean之间的相互转换

    当前台需要传送一系列相似数据到后端时,可以考虑将其组装成json数组对象,然后转化为json形式的字符串传输到后台 例如: nodes = $('#PmPbsSelect_tree').tree('g ...

  10. Spark集群任务提交流程----2.1.0源码解析

    Spark的应用程序是通过spark-submit提交到Spark集群上运行的,那么spark-submit到底提交了什么,集群是怎样调度运行的,下面一一详解. 0. spark-submit提交任务 ...