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.原因,工作队列被占用,只需 ...
随机推荐
- css 常见兼容性问题及解决方案
css 兼容问题一直是困扰前端开发人员的大难题,提到兼容性立马想到了万恶的ie6,说多了都是泪,还是整理一些常见的兼容性问题以及解决的方案吧. 一. 浮动元素双边距. ①条件:ie6下,如果给元素设置 ...
- [转]JavaScript作用域安全构造函数
构造函数其实就是一个使用new操作符调用的函数.当使用new调用时,构造函数内用到的this对象会对指向新创建的对象实例,如下的例子所示: function Person(name, ag ...
- react 组件开发
参考资料 https://toddmotto.com/react-create-class-versus-component/ React-Native的代码规范,React其实也基本一样~~ htt ...
- Android_常用控件及适配器
TextView 控件中显示的内容必须是文本 TextView中常用的属性 android:text TextView中显示的文本内容 android:textColor 字体颜色 格式为#RGB # ...
- Spring MVC中如何传递对象参数
springController: @Controller @RequestMapping("/user") public UserController extends BaseC ...
- sql 几个常用函数
ROUND 用法: --15.000 表示小数点第一位取四舍五入,将原小数点后的位数都设置为0SELECT ROUND(15.258,0) --15.300,第二个参数如果是1,则取原值小数点后第一位 ...
- swift-08-使用键值对儿统计字符在字符串中出现的次数
// // main.swift // 12- // // Created by wanghy on 15/8/9. // Copyright (c) 2015年 wanghy. All ri ...
- (poj)3414 Pots (输出路径的广搜)
Description You are given two pots, having the volume of A and B liters respectively. The following ...
- 选择第n小的元素之python实现源码
def partition(A, p, r): j = p+1 for i in range(p+1, r+1): if(A[i] < A[p]): tmp = A[i] A[i] = A[j] ...
- 模板:优先队列(priority_queue)
#include <iostream> #include <cstdio> #include <queue> #include <vector> usi ...