题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1287

题意:给定一个n个点的无向图(0到n-1),你开始在0。你开始遍历这个图,每个点只能被遍历一次。当你在某个点u时,假设u可以到达v1,v2且到达v1或者v2后均可以将其他未遍历的点遍历完,则你在u有三种选择:1、在u再呆5分钟;2、去v1,;3、去v2。概率均为1/3。求遍历完整个图的时间期望。

思路:f[u]=(5+f[u])/(x+1)+(g[u][vi]+f[vi])/(x+1),1<=i<=x,x为合法的下一个点。。

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int INF=1000000000;
int C,num=0;
int n,m,g[15][15];
double f[15][1<<15];
bool visit[15][1<<15]; int DFS(int st,int u)
{
if(st==(1<<n)-1)
{
f[u][st]=0;
return 1;
}
if(visit[u][st]) return f[u][st]>1e-10;
visit[u][st]=1;
f[u][st]=5;
int i,st0,cnt=0;
for(i=0;i<n;i++) if(!(st&(1<<i))&&g[u][i]!=INF&&DFS(st|(1<<i),i))
{
st0=st|(1<<i);
f[u][st]+=g[u][i]+f[i][st0];
cnt++;
}
if(!cnt)
{
f[u][st]=0;
return 0;
}
f[u][st]/=cnt;
return 1;
} int main()
{
for(scanf("%d",&C);C--;)
{
scanf("%d%d",&n,&m);
int i,j,u,v,w;
for(i=0;i<n;i++) for(j=0;j<n;j++) g[i][j]=INF;
for(i=1;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&w);
g[u][v]=g[v][u]=w;
}
memset(visit,0,sizeof(visit));
DFS(1,0);
printf("Case %d: %.6lf\n",++num,f[0][1]);
}
return 0;
}

  

LightOJ 1287 Where to Run(期望)的更多相关文章

  1. LightOJ - 1287 Where to Run —— 期望、状压DP

    题目链接:https://vjudge.net/problem/LightOJ-1287 1287 - Where to Run    PDF (English) Statistics Forum T ...

  2. LightOJ - 1287 Where to Run (期望dp+记忆化)

    题面: Last night you robbed a bank but couldn't escape and when you just got outside today, the police ...

  3. [LightOJ 1287] Where to Run

    Where to Run Last night you robbed a bank but couldn't escape and when you just got outside today, t ...

  4. Where to Run LightOJ - 1287(概率dp)

    Where to Run LightOJ - 1287(概率dp) 题面长长的,看了半天也没看懂题意 不清楚的地方,如何判断一个点是否是EJ 按照我的理解 在一个EJ点处,要么原地停留五分钟接着走,要 ...

  5. LightOJ 1030 Discovering Gold(期望)

    Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...

  6. LightOJ - 1274 Beating the Dataset —— 期望

    题目链接:https://vjudge.net/problem/LightOJ-1274 1274 - Beating the Dataset    PDF (English) Statistics ...

  7. LightOj:1030-Discovering Gold(期望dp模板)

    传送门:http://www.lightoj.com/volume_showproblem.php?problem=1030 Discovering Gold Time Limit: 2 second ...

  8. LightOJ 1030 Discovering Gold (概率/期望DP)

    题目链接:LightOJ - 1030 Description You are in a cave, a long cave! The cave can be represented by a \(1 ...

  9. LightOJ 1030 Discovering Gold (期望)

    https://vjudge.net/problem/LightOJ-1030 题意: 在一个1×N的格子里,每个格子都有相应的金币数,走到相应格子的话,就会得到该格子的金币. 现在从1格子开始,每次 ...

随机推荐

  1. Scratch 第2课淘气男孩儿

    素材及视频下载 链接:https://pan.baidu.com/s/1qX0T2B_zczcLaCCpiRrsnA提取码:xfp8

  2. 2059 - Authentication plugin 'caching_sha2_password' cannot be loaded dlope

    今天在mac上使用navicat连接mysql报错弄了一下午,各种查询踩坑,总算解决了. 即从mysql5.7版本之后,默认采用了caching_sha2_password验证方式,我用的mysql8 ...

  3. 通过简单的ajax验证是否存在已有的用户名

    首先来说说我对ajax的理解:简单地来说就是在不重新刷新页面的情况下,实现数据的调用获得更新. 我在这里介绍的是要过jquery封装好的ajax,大家可以去了解一下使用原生的XMLHttpReques ...

  4. 一、华为模拟器eNSP下载与安装教程

    简单介绍一下 eNSP: eNSP是一款由华为提供的免费的图形化网络仿真工具平台,它将完美呈现真实设备实景(包括华为最新的ARG3路由器和X7系列的交换机),支持大型网络模拟,让你有机会在没有真实设备 ...

  5. Django-rest-framework 是个什么鬼?

    作者:HelloGitHub-追梦人物 我们首先来回顾一下传统的基于模板引擎的 django 开发工作流: 绑定 URL 和视图函数.当用户访问某个 URL 时,调用绑定的视图函数进行处理. 编写视图 ...

  6. alg-最长不重复子串

    class Solution { public: int lengthOfLongestSubstring(const std::string& s) { int max_length = 0 ...

  7. Apache与PHP的配置

    Listen 表示端口号 ServerName 表示域名 <Directory 路径> 表示默认开放的路径 <IfModule dir_module> 表示默认显示的文件名 & ...

  8. AJ学IOS(02)UI之按钮操作 点击变换 移动 放大缩小 旋转

    不多说,先上图片看效果,AJ分享,必须精品 这个小程序主要实现点击方向键可以让图标上下左右动还有放大缩小以及旋转的功能,点击图片会显示另一张图片. 点击变换 其实用到了按钮的两个状态,再State C ...

  9. python基础之函数详解

    Python基础之函数详解 目录 Python基础之函数详解 一.函数的定义 二.函数的调用 三.函数返回值 四.函数的参数 4.1 位置参数 4.2 关键字参数 实参:位置实参和关键字参数的混合使用 ...

  10. 常见web漏洞整理之进击吧xss!!!

    XSS在线测试环境: http://xss-quiz.int21h.jp/ https://brutelogic.com.br/xss.php 这两个站对xss的理解很有帮助!!! 参考链接: htt ...