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并从第一关开始,先要求通过所有关卡的时间和不 ...
随机推荐
- kube-dns和coreDNS的使用
内部服务发现 前面我们给大家讲解了 Service 的用法,我们可以通过 Service 生成的 ClusterIP(VIP)来访问 Pod 提供的服务,但是在使用的时候还有一个问题:我们怎么知道某个 ...
- Python文件操作——读写图片,音频,视频
注意:其实就是将mode="rb"或者mode="wb",因为图片,视频,音频就是二进制进行读取,b 代表binary ,其他的和一般文件操作步骤一样,另外, ...
- react 管理平台
https://open.vbill.cn/react-admin/ 开源中国:https://gitee.com/sxfad/react-admin.git GitHub:https://githu ...
- 使用百度echarts仿雪球分时图(四)
这章节来收拾一下一些小BUG,顺便把各个小提示信息也补上,分时图也就完成了. 上章节末尾提到的一个bug,就是第一个grid跟第三个grid之间是断开的,折线并没有连在一起,所以先来收拾这个问题.没有 ...
- Python学习记录3-函数参数详解
参数详解 参数分类 普通参数 默认参数 关键字参数 收集参数 普通参数 定义时直接定义变量名 调用的时候直接把变量或者值放入指定位置 def 函数名 (参数1, 参数2, ....): 函数体 # 调 ...
- python中的网络通信,socket、select、selectors、socketserver
楔子 网络通信用于获取一个算法在本地运行所需的数据,还可以共享信息实现分布式处理,另外可以用来管理云服务. python的标准库提供了一些模块来创建网络服务以及访问现有服务ipaddress模块提供了 ...
- Python GUI--Tkinter简单实现个性签名设计
一.Tkinter的介绍和简单教程Tkinter 是 Python 的标准 GUI 库.Python 使用 Tkinter 可以快速的创建 GUI 应用程序.由于 Tkinter 是内置到 pytho ...
- HDU 6415 Rikka with Nash Equilibrium (计数DP)
题意:给两个整数n,m,让你使用 1 ~ n*m的所有数,构造一个矩阵n*m的矩阵,此矩阵满足:只有一个元素在它的此行和此列中都是最大的,求有多种方式. 析:根据题意,可以知道那个元素一定是 n * ...
- SARS病毒 (生成函数 + 快速幂)
链接:https://ac.nowcoder.com/acm/contest/992/A来源:牛客网 题目描述 目前,SARS 病毒的研究在世界范围内进行,经科学家研究发现,该病毒及其变种的 DNA ...
- GLSLPROGRAM METALPROGRAM unity
https://docs.unity3d.com/Manual/SL-GLSLShaderPrograms.html unity里面可以直接写原生的shader 用相应的宏包起来 CGPROGRAM ...