题目链接

题意:

  有n个街口和m条街道, 你后边跟着警察,你需要进行大逃亡(又是大爱的抢银行啊),在每个街口你都有≥1个选择,

  1)停留在原地5分钟。

  2)如果这个街口可以到xi这个街口, 并且, 通过xi可以遍历完所有未走过的街口,那么就加入选择。

  每个选择都是等概率的。

  求警察抓住你所用时间的期望, 即你无路可走时的时间期望。

思路:

  对于每个点, 先找出所有的选择, 假设有k个选择。

  那么E[i] 表示在街口i时被抓的时间期望。

  则, E[i] = 1 / k * sigma (E[u] + time[i][u]) + 1 / k * (E[i] + 5)。

    化简得:E[i] = (sigma (E[u] + time[i][u]) + 5) / (k - 1)

  用staues表示从i点出发, 到达状态staues所用的期望, 即所经历的点。  

代码:

  

 #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <vector>
#include <fstream>
#include <iterator>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define eps 1e-7
#define MAXN 110
#define MAXM 16
#define dd cout<<"debug"<<endl
#define p(x) printf("%d\n", x)
#define pd(x) printf("%.7lf\n", x)
#define k(x) printf("Case %d: ", ++x)
#define s(x) scanf("%d", &x)
#define sd(x) scanf("%lf", &x)
#define mes(x, d) memset(x, d, sizeof(x))
#define f(i, x) for(i = 0; i < x; i ++)
int n, m;
int w[MAXN][MAXN];
double E[MAXM][ << MAXM];
bool vis[MAXM][ << MAXM]; bool dfs(int staues, int root)
{
if(staues == ( << n) - )
{
E[root][staues] = ;
return true;
}
if(vis[root][staues]) return E[root][staues] > ;
vis[root][staues] = true;
E[root][staues] = ;
int cnt = , sttemp;
int i;
f(i, n)
if(!(staues & ( << i)) && w[root][i] != INF && dfs((staues | ( << i)), i))
{
sttemp = staues | ( << i);
cnt ++;
E[root][staues] += w[root][i] + E[i][sttemp];
}
if(!cnt)
{
E[root][staues] = ;
return false;
}
E[root][staues] /= cnt;
return true;
} int main()
{
int T;
int kcase = ;
s(T);
while(T --)
{
int u, v;
int ww;
s(n), s(m);
mes(w, 0x3f);
mes(vis, false);
int i;
f(i, m)
{
s(u), s(v), s(ww);
w[u][v] = w[v][u] = ww;
}
dfs(, );
k(kcase), pd(E[][]);
}
return ;
}

LightOj_1287 Where to Run的更多相关文章

  1. can't run roscore 并且 sudo 指令返回 unable to resolve host

    I'm using ubuntu14 LTS. Problems: 1. When run roscore, got a mistake and an advice to ping the local ...

  2. DotNet Run 命令介绍

    前言 本篇主要介绍 asp.net core 中,使用 dotnet tools 运行 dotnet run 之后的系统执行过程. 如果你觉得对你有帮助的话,不妨点个[推荐]. 目录 dotnet r ...

  3. 布里斯班Twilight Bay Run半程马拉松

    自从8月3日跑了半马以后,又一鼓作气报了11月份的西昌马拉松.与第一次马拉松的只求完赛目标不同,第二次当然想取得一个更好的成绩.所以8月份练的比较猛,基本上是练2.3天休息一天,周么还要拉个长于21公 ...

  4. SVN:Previous operation has not finished; run 'cleanup' if it was interrupted

    异常处理汇总-开发工具  http://www.cnblogs.com/dunitian/p/4522988.html cleanup failed to process the following ...

  5. linux 环境下运行STS时 出现must be available in order to run STS

    linux 环境下运行ECLIPSE时 出现 “ A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be avai ...

  6. 0040 Java学习笔记-多线程-线程run()方法中的异常

    run()与异常 不管是Threade还是Runnable的run()方法都没有定义抛出异常,也就是说一条线程内部发生的checked异常,必须也只能在内部用try-catch处理掉,不能往外抛,因为 ...

  7. jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.

    jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...

  8. .NET跨平台之旅:探秘 dotnet run 如何运行 .NET Core 应用程序

    自从用 dotnet run 成功运行第一个 "Hello world" .NET Core 应用程序后,一直有个好奇心:dotnet run 究竟是如何运行一个 .NET Cor ...

  9. 【svn】在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted

    1.svn在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted2.原因,工作队列被占用,只需 ...

随机推荐

  1. 从零开始,打造自己的首个 iOS 框架

    如果你曾试图创建自己的iOS框架,你知道这不是一个头脑发热作出的决定 — 管理依赖以及写测试用例一点也不简单.本教程将会带你从头到尾创建你的第一个iOS框架,让你可以创建自己的框架. 我们将在框架暴露 ...

  2. 使用HttpURLConnection实现在android客户端和服务器之间传递对象

    一般情况下,客户端和服务端的数据交互都是使用json和XML,相比于XML,json更加轻量级,并且省流量,但是,无论我们用json还是用xml,都需要我们先将数据封装成json字符串或者是一个xml ...

  3. 解决DataTable中的DataColumn类型默认为int类型时, 导致不能修改其列值为其他类型的解决办法

    问题起因: 扔给数据库一条select * from [表名] , 得到一个DataTable, 发现有一列status状态的DataColumn的类型是int,然后我想换成字典表里的文字描述,然后就 ...

  4. (转)OpenVPN下载、安装、配置及使用详解

    原文地址:http://www.365mini.com/page/14.htm OpenVPN简介 OpenVPN是一个用于创建虚拟专用网络(Virtual Private Network)加密通道的 ...

  5. 有理数类 Java

    public class Rational extends Number implements Comparable { private long numerator;// 分子 private lo ...

  6. Object-C属性(Properties)

    前面我们写了caption和photographer的访问方法,你可能也注意到了,那些代码很简单,应该可以写成具有更普遍意义的形式. 属性是Object-C的一个特性,它允许我们自动生成访问器,同时还 ...

  7. java新手笔记16 面积

    1.图形类 package com.yfs.javase; public class Shape { //计算面积方法 public double getArea() { System.out.pri ...

  8. 手把手教你写电商爬虫-第四课 淘宝网商品爬虫自动JS渲染

    版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 手把手教你写电商爬虫-第三课 ...

  9. IntelliJ IDEA14 和 Maven 系列:使用IntelliJ IDEA 14和Maven 7 创建java web项目(一)

    Intellij IDEA作为最好的Java IDE,创建Maven项目还是比较简单的,但是创建一个Maven Web项目还是要修改一些配置的,下面进行总结整理. 1前言 在创建项目中,IDEA提供了 ...

  10. Linux apt-get error

    csh@csh-laptop:~/ejabberd-15.03$ sudo apt-get install mysqlReading package lists... DoneBuilding dep ...