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并从第一关开始,先要求通过所有关卡的时间和不 ...
随机推荐
- List和Dictionary互转
// 声明Dictionary并初始化 Dictionary<string, string> dic = new Dictionary<string, string>() { ...
- Signalr Vue Echarts绘制实时CPU使用率
后端基于Asp.net webapi,前端Vue,前后端分离,该demo仅做演示,实现的细节可以自己优化 Echarts:4.2.1 可参考 官网 Jquery:3.4.1 Signalr:2.4. ...
- 关于EF数据迁移的个人总结 简单有效
有用的拿走,没用的嘴下留情!
- redis 命令行操作报错
向redis集群写数据抛异常:(error) MOVED 15342 2001:fecc:0:616::34:6383 原因是启动redis-cli时未以集群方式启动,即后面要加上 -c redis- ...
- 使用百度地图API自动获取地址和经纬度
先上效果图,这是直接点击获取经纬度和地址的.没有做搜索的功能. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...
- Oracle权限管理详解(2)
详见:https://blog.csdn.net/u013412772/article/details/52733050 Oracle数据库推荐以引用博客: http: http:.html http ...
- 阿里十年架构师告诉你Spring Boot与Spring Cloud是什么关系
SpringBoot先于Spring Cloud问世.SpringBoot相当于脚手架,借助他可以快速搭建房子,它本身不具备任何功能属性,值是普通房间,没有其他任何功能. 什么是Spring Boot ...
- etcd简单测试类java版
为了方便现场安装完了etcd集群后确认集群是否好用,简单写了个测试类,网上搜的有点乱还有些不能运行,在这里再整理一个能够直接运行的 1.我把etcd的API设成3版本了,调用使用的jetcd,功能挺多 ...
- kubernetes之Taints污点和Tolerations容忍
介绍说明 nodeaffinity节点亲和性是pod上定义的一种属性, 使得pod能够被调度到某些node上运行, taint污点正好相反, 它让node拒绝pod运行, 除非pod明确声明能够容忍这 ...
- 微信小程序开发(十一)获取手机的完整详细信息
// succ.wxml <view style='position:absolute; top:30%; left:35%;font-size:36rpx'>{{name}}:签到成功. ...