LightOj_1287 Where to Run
题意:
有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的更多相关文章
- 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 ...
- DotNet Run 命令介绍
前言 本篇主要介绍 asp.net core 中,使用 dotnet tools 运行 dotnet run 之后的系统执行过程. 如果你觉得对你有帮助的话,不妨点个[推荐]. 目录 dotnet r ...
- 布里斯班Twilight Bay Run半程马拉松
自从8月3日跑了半马以后,又一鼓作气报了11月份的西昌马拉松.与第一次马拉松的只求完赛目标不同,第二次当然想取得一个更好的成绩.所以8月份练的比较猛,基本上是练2.3天休息一天,周么还要拉个长于21公 ...
- 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 ...
- 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 ...
- 0040 Java学习笔记-多线程-线程run()方法中的异常
run()与异常 不管是Threade还是Runnable的run()方法都没有定义抛出异常,也就是说一条线程内部发生的checked异常,必须也只能在内部用try-catch处理掉,不能往外抛,因为 ...
- 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 ...
- .NET跨平台之旅:探秘 dotnet run 如何运行 .NET Core 应用程序
自从用 dotnet run 成功运行第一个 "Hello world" .NET Core 应用程序后,一直有个好奇心:dotnet run 究竟是如何运行一个 .NET Cor ...
- 【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.原因,工作队列被占用,只需 ...
随机推荐
- C++面试题算法
#include <iostream> #include <string> using namespace std ; /* 题目:给一个字符串.例如 "ababc& ...
- 一个App带你学会Retrofit2.0,麻麻再也不用担心我的网络请求了!
Retrofit.Retrofit.Retrofit,越来越多的人在玩这个网络请求框架,这个由squareup公司开源的网络请求框架确实挺好用,今天我们就来看一下这个东东怎么玩! Retrofit作为 ...
- update 改写 merge into
update语句改写成merge into有时会提高运行速度 看两个案例 1.根据业务将两个嵌套子查询改写成max,速度有3min提升到3s UPDATE OPER_792.LL_SCB_YDKB_2 ...
- Linux 下mysql忘记root密码解决方法
忘记root密码怎么办:1.关闭数据库2.使用-->mysqld_safe --skip-grant-tables &--<启动数据库3.使用空密码进入数据库(mysql命令后直接 ...
- JUnit4简要说明
单元测试(unit testing),是指对软件中的最小可测试单元进行检查和验证. 开发者编写一小段代码,用于检验被测代码的一个很小的.很明确的功能是否正确. 通常而言,一个单元测试是用于判断某个特定 ...
- ThinkPHP函数详解:cache方法
cache方法是3.0版本开始新增的缓存管理方法.注意:3.1.2版本后因cache方法并入原S方法,所以cache方法不再建议使用,用S方法即可. cache 用于缓存设置.获取.删除操作 用法ca ...
- SecurityException:Not allowed to start service Intent ,without permission not exported from
本来是学长以前的项目,我正在重做一遍.结果突然出现了异常,我很是不解啊,怎么莫名其妙的就出现异常了呢?我昨天用还是好好的,根本就没动过源代码.于是在网上开始了一遍又一遍的查询,有的说要加权限.有的说这 ...
- cmd命令积累
dir:展示所有目录 cd fileName:进入下一个目录 cd .. :返回上一层目录 cd\:返回根目录
- kafka环境搭建2-broker集群+zookeeper集群(转)
原文地址:http://www.jianshu.com/p/dc4770fc34b6 zookeeper集群搭建 kafka是通过zookeeper来管理集群.kafka软件包内虽然包括了一个简版的z ...
- c编程:用户输入一个数值n,打印出出1到n之间的所有质数
#include <stdio.h> int func(int i ) { //定义一个变量temp=2,当主函数引入的数大于temp时进入for循环.当它在比自己小的数中找到一个能背整除 ...