题目链接

题意:

  有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. sqrt 源代码

    stap -v -e 'probe process("/usr/local/mysql56/bin/mysqld").function("*@/usr/src/mysql ...

  2. iOS开发简单高效的数据存储

    在iOS开发过程中,不管是做什么应用,都会碰到数据保存的问题,你是用什么方法来持久保存数据的?这是在几乎每一次关于iOS技术的交流或讨论都会被提到的问题,而且大家对这个问题的热情持续高涨.本文主要从概 ...

  3. JVM笔记7:类加载器

    虚拟机设计团队把类加载阶段中的"通过一个类的全限定名来获取描述此类的二进制字节流"这个动作放到Java虚拟机外部实现,以便让应用程序自己决定如何去获取所需要的类,实现这个动作的代码 ...

  4. Java json设置时间格式,Jackson设置时间格式,json设置单引号

    Java json设置时间格式,Jackson设置时间格式,json设置单引号 >>>>>>>>>>>>>>> ...

  5. css placeholder 颜色设置

    因为每个浏览器的CSS选择器都有所差异,所以需要针对每个浏览器做单独的设定(可以在冒号前面写input和textarea). ::-webkit-input-placeholder { /* WebK ...

  6. SecurityException:Not allowed to start service Intent ,without permission not exported from

    本来是学长以前的项目,我正在重做一遍.结果突然出现了异常,我很是不解啊,怎么莫名其妙的就出现异常了呢?我昨天用还是好好的,根本就没动过源代码.于是在网上开始了一遍又一遍的查询,有的说要加权限.有的说这 ...

  7. Ext.Net学习笔记04:Ext.Net布局

    ExtJS中的布局功能很强大,常用的布局有border.accordion.fit.hbox.vbox等,Ext.Net除了将这些布局进行封装以外,更是对border进行了一些非常实用的改进,让我们来 ...

  8. java- 枚举的常见用法

    用法一:常量 public enum MyColor{Red,Black,Blue} public enum Color { RED, GREEN, BLANK, YELLOW } enum为枚举类的 ...

  9. 常用JS正则表达式收集

    1.去掉字符串前后空格,不会修改原有字符串,返回新串.str.replace(/(^\s*)|(\s*$)/g,'');

  10. JAVA IDE下载地址

    Subclipse 各版本官网下载地址: http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 Eclipse ...