传送门

显然这个图是个 $DAG$ ,那么就可以考虑跑 $dp$ 了

先考虑没有梯子的情况,首先把每个位置标号,越后面的位置编号越小,终点位置编号为 $1$

那么从终点往起点 $dp$ ,枚举当前位置摇到的数字,那么有 $f[x]=\frac{\sum_{i=1}^{6}(f[x-i]+1)}{6}$,并且 $f[1]=0$

但是这是在 $x>6$ 的情况下成立的,因为如果 $x<=6$ 那么有可能不走,特殊考虑一下

首先 $f[2]$ ,那么有 $5/6$ 的概率原地不动,$1/6$ 的概率走到终点,即 $f[2]=\frac{5(f[2]+1)}{6}+\frac{f[1]+1}{6}=(\frac{5}{6}+\frac{f[1]+1}{6}) / (1-5/6)$

然后 $f[3]$ 也差不多考虑,$f[3]=\frac{4(f[3]+1)}{6}+\frac{f[1]+1}{6}+\frac{f[2]+1}{6}=(\frac{4}{6}+\frac{f[1]+1}{6}+\frac{f[2]+1}{6}) / (1-4/6)$

发现对于 $x\in [2,6]$ ,$f[x]=\frac{(\sum_{i=1}^{x-1}f[x-i]+1)/6+(7-i)/6}{1-(7-i)/6}$

现在来考虑有梯子的情况,设位置 $x$ 有一个梯子通往位置 $y$ ,那么 $f[x]$ 转移的时候还要考虑瞬移到 $y$ 再走的情况

差不多的转移,取个最小值即可,即和 $\sum_{i=1}^{6}(f[y-i]+1)/6$ 取个最小值,对于 $y<=6$ 的情况同样要特殊处理

看代码就知道具体怎么做了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
typedef double db;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int n=,N=;
int id[N][N],to[N];
db f[N];
int main()
{
int tot=;
for(int i=;i<=n;i++)
{
if(i&)
for(int j=;j<=n;j++)
id[i][j]=++tot;
else
for(int j=n;j>=;j--)
id[i][j]=++tot;
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
int a=read();
if(a) to[id[i][j]]=id[i-a][j];
}
// f[2]=(f[2]+1)*5/6 + 1/6
// f[3]=(f[3]+1)*4/6 + 1/6 + (f[2]+1)/6
for(int i=;i<=;i++)
{
for(int j=;j<i;j++)
f[i]+=(f[i-j]+1.0)/;
f[i]+=(7.0-i)/;
f[i]/=(1.0-(7.0-i)/);
}
for(int i=;i<=tot;i++)
{
for(int j=;j<=;j++)
f[i]+=(f[i-j]+1.0)/;
if(!to[i]) continue;
db mi=; int t=to[i];
if(t==) { f[i]=; continue; }//我这个做法要特判
for(int j=;j<=;j++)
if(t-j>) mi+=(f[t-j]+1.0)/;
if(t<=) mi+=(7.0-t)/,mi/=(1.0-(7.0-t)/);
f[i]=min(f[i],mi);
}
printf("%.10f\n",f[tot]);
return ;
}

Codeforces 1245 E. Hyakugoku and Ladders的更多相关文章

  1. Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp

    E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black ...

  2. CF1245E:Hyakugoku and Ladders

    CF1245E:Hyakugoku and Ladders 题意描述: 给你一个\(10*10\)的矩阵,矩阵描述如下 最开始的时候你在左下角,你的目标是到达左上角. 你可以走路径或者爬梯子. 路径的 ...

  3. codeforces 597 div2 E. Hyakugoku and Ladders(概率dp)

    题目链接:https://codeforces.com/contest/1245/problem/E 题意:有一个10x10的网格,左下角是起点,左上角是终点,从起点开始,如图所示蛇形走到终点,每一步 ...

  4. CodeForces - 1245 C - Constanze's Machine

    Codeforces Round #597 (Div. 2) Constanze is the smartest girl in her village but she has bad eyesigh ...

  5. CodeForces - 1245 B - Restricted RPS(贪心)

    Codeforces Round #597 (Div. 2) Let nn be a positive integer. Let a,b,ca,b,c be nonnegative integers ...

  6. Codeforces 1245 D. Shichikuji and Power Grid

    传送门 经典的最小生成树模型 建一个点 $0$ ,向所有其他点 $x$ 连一条边权为 $c[x]$ 的边,其他任意两点之间连边,边权为 $(k_i+k_j)(\left | x_i-x_j\right ...

  7. Codeforces Round #597 (Div. 2)

    A - Good ol' Numbers Coloring 题意:有无穷个格子,给定 \(a,b\) ,按以下规则染色: \(0\) 号格子白色:当 \(i\) 为正整数, \(i\) 号格子当 \( ...

  8. 并不对劲的CF1245E&F:Cleaning Ladders

    CF1245 E. Hyakugoku and Ladders 题目大意 有一个10 \(\times\) 10的网格,你要按这样的路径行走: 网格中有一些单向传送门,每个传送门连接的两个格子在同一列 ...

  9. some problem

    CF1257F Make Them Similar $solution:$ 折半搜索后考虑如何维护两个数组的和,可以将 $A$ 中每个数减 $A_1$ ,$B$ 中每个数被减 $B_1$ ,$map$ ...

随机推荐

  1. flask上下文流程面试总结

  2. mysql存储引擎介绍,索引

    区别: MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持.MyISAM类型的表强调的是性能,其执行数度比InnoDB类型更快,但是不提供事务支持,而InnoDB提供事务支持已经外部键等 ...

  3. angular自定义组件

    https://cli.angular.io/ 打开终端创建header组件: ng g component components/header import { Component, OnInit ...

  4. Build Telemetry for Distributed Services之OpenCensus:Tracing2(待续)

    part 1:Tracing1 Sampling Sampling Samplers Global sampler Per span sampler Rules References

  5. SpringCloud学习成长 四 断路器(Hystrix)

    在微服务架构中,根据业务来拆分成一个个的服务,服务与服务之间可以相互调用(RPC),在Spring Cloud可以用RestTemplate+Ribbon和Feign来调用.为了保证其高可用,单个服务 ...

  6. LeetCode_160. Intersection of Two Linked Lists

    160. Intersection of Two Linked Lists Easy Write a program to find the node at which the intersectio ...

  7. (十九)oracle 基础使用以及sql语句基础

    oracle的安装与卸载 要记住数据库口令,适用于sys.system.sysman/dbsnmp等账户,而scott帐号密码默认为tiger, 以oracle  10g来说,scott账户默认是lo ...

  8. python 函数、参数及参数解构

    函数 数学定义 y=f(x), y是x函数,x是自变量.y=f(x0,x1...xn) Python函数 由若干语句组成的语句块,函数名称,参数列表构成,它是组织代码的最小单位 完成一定的功能 函数作 ...

  9. mysql使用truncate截断带有外键的表时报错--解决方案

    报错内容如:1701 - Cannot truncate a table referenced in a foreign key constraint 一.为什么要使用truncate 使用trunc ...

  10. 第十一章 缓存机制——《跟我学Shiro》

    转发地址:https://www.iteye.com/blog/jinnianshilongnian-2029217 跟我学Shiro  目录贴:跟我学Shiro目录贴 Shiro提供了类似于Spri ...