codeforces865C
Gotta Go Fast
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
1 8
2 8 81
3.14
2 30
20 30 80
3 9 85
31.4
4 319
63 79 89
79 97 91
75 87 88
75 90 83
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的更多相关文章
- #3 Codeforces-865C Gotta Go Fast(期望dp)
题意:一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每通过一关后可以选择继续下一关或者时间清0并从第一关开始,先要求通过所有关卡的时间和不 ...
随机推荐
- linux下shell 脚本 中windows换行符换成linux换行符
sed -i 's/\r//' filename window下默认是 \r\n linux下是\n unix下是\r
- getContextPath、getServletPath、getRequestURI、getRealPath、getRequestURL、getPathInfo();的区别
<% out.println("getContextPath: "+request.getContextPath()+"<br/>"); ou ...
- MyBatis Java不同方式加载文件时的路径格式问题、Mybatis中加载.properties文件
public class LoadPropTest { public static void main(String[] args) throws IOException { //一.Properti ...
- android 自定义控件之NetWorkImageView 处理listview等控件中的图片加载乱序问题
0.调用: BaseAdapter中设置方法 holder.iv.loadImage(url); adapter_xxx.xml 中 控件需要用 xxx.NetWorkImageView 1 NetW ...
- Node.js学习(1)-加载模块require('fs/http/.b/art-template')
node.js既不是语言,也不是框架,它是一个平台 加载模块: 核心模块(require('fs/http')), 自定义模块(var bExport=require('./b'),exports.f ...
- git 分布式版本控制
一.git版本控制 管理文件夹 安装省略 1. 进入要管理的文件夹 2. 初始化 (提名) 3. 管理 4. 生成版本 对应的命令: # 进入文件夹以后 右击选git bash here #初始化 g ...
- deep_learning_学习资料
TensorFlow的55个经典案例:https://blog.csdn.net/xzy_thu/article/details/76220654 吴恩达机器学习: 1.序列学习:https://mo ...
- Git修改已经提交的用户名信息
由于工作或者其他原因,有时候我们会修改git的用户名和邮箱账号,没有改过来就提交,就会导致提交人信息不一致的问题.现在记录修正回来的方法 # 第一步,(n)代表提交次数 git rebase -i H ...
- Repeater POJ - 3768 (分形)
Repeater POJ - 3768 Harmony is indispensible in our daily life and no one can live without it----may ...
- Python之datetime模块
datatime模块重新封装了time模块,提供更多接口,提供的类有:date,time,datetime,timedelta,tzinfo. 1.date类 datetime.date(year, ...