[cf113d]Museum
传送门
Solution
设一个状态为 \((x,y)\) 表示两人在的位置,求出每个状态期望出现的次数
设一个状态为 \(u\) , \(x_u^0=[u==(a,b)]\)
所以一个状态出现的次数期望为 \(E_u=x_u^0+\sum_vG(v,u)\times E_v\)
其中\(G\)是状态转移的概率矩阵
高消即可,复杂度 \(O(n^6)\)
Code
#include<bits/stdc++.h>
#define ll long long
#define db double
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
const int MN=23;bool A[MN][MN];
int I[MN][MN],N,M,a,b,deg[MN];
db B[MN*MN][MN*MN],F[MN*MN],P[MN];
void Gauss(int n)
{
reg int i,j,k;
for(i=1;i<=n;++i)
{
int p=i;
for(j=i+1;j<=n;++j)if(fabs(B[j][i])>fabs(B[p][i]))p=j;
if(i!=p)swap(B[i],B[p]);
for(j=i+1;j<=n;++j)
{
db d=B[j][i]/B[i][i];
for(k=i;k<=n+1;++k) B[j][k]-=d*B[i][k];
}
}
for(i=n;i;--i)
{
for(j=i+1;j<=n;++j)B[i][n+1]-=F[j]*B[i][j];
F[i]=B[i][n+1]/B[i][i];
}
}
db _(int x,int y){if(!A[x][y])return 0;if(x==y)return P[x];return (1.-P[x])/deg[x];}
int main()
{
reg int i,j,x,y;
N=read(),M=read();a=read(),b=read();
for(i=1;i<=M;++i) x=read(),y=read(),++deg[x],++deg[y],A[x][y]=A[y][x]=1;
for(i=1;i<=N;++i) A[i][i]=1,scanf("%lf",&P[i]);
for(i=1;i<=N;++i)for(j=1;j<=N;++j)I[i][j]=(i-1)*N+j;
B[I[a][b]][N*N+1]=-1.;
for(i=1;i<=N;++i)for(j=1;j<=N;++j)
{
B[I[i][j]][I[i][j]]+=-1.;
if(i!=j)for(x=1;x<=N;++x)for(y=1;y<=N;++y) B[I[x][y]][I[i][j]]+=_(i,x)*_(j,y);
}
Gauss(N*N);
for(i=1;i<=N;++i) printf("%.10lf ",F[I[i][i]]);
return 0;
}
Blog来自PaperCloud,未经允许,请勿转载,TKS!
[cf113d]Museum的更多相关文章
- cf113D. Museum(期望 高斯消元)
题意 题目链接 Sol 设\(f[i][j]\)表示Petya在\(i\),\(Vasya\)在\(j\)的概率,我们要求的是\(f[i][i]\) 直接列方程高斯消元即可,由于每个状态有两维,因此时 ...
- 【CF113D】Museum
Portal --> cf113D Solution 额题意的话大概就是给一个无向图然后两个人给两个出发点,每个点每分钟有\(p[i]\)的概率停留,问这两个人在每个点相遇的概率是多少 如果说我 ...
- Solution -「CF113D」Museum
Upd 2021.10.21 更改了状态定义. 记 \(S(u)\) 表示 \(u\) 结点的相邻结点的集合. 又记 \(p(u)\) 表示走到了 \(u\) 且下一步继续留在 \(u\) 结点的概率 ...
- UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形)
Sackler Museum of Art and Archaeology at Peking University is located on a beautiful site near the W ...
- Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集
D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...
- Igor In the Museum(搜搜搜151515151515******************************************************1515151515151515151515)
D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...
- A. Night at the Museum Round#376 (Div. 2)
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
- [codeforces113D]Museum
D. Museum time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input ...
- Codeforces 376A. Night at the Museum
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- springboot+RabbitMQ 问题 RabbitListener 动态队列名称:Attribute value must be constant
因为多机环境fanout广播模式,每台机器需要使用自己的队列接受消息 所以尝试使用以下的方案 private static final String QUEUE_NAME="foo.&quo ...
- 轻量级搜索工具【Everything】的设置
下面是我对 轻量级搜索工具[Everything]的设置 Everything 下载地址:http://www.voidtools.com/downloads/ 1. 排除 Windows => ...
- 【IntelliJ IDEA】idea部署服务到Tomcat的工作原理
参考地址: https://blog.csdn.net/qq_41116058/article/details/81435084 为什么idea部署服务到tomcat时候,一定要修改Applicati ...
- 15、VUEX-Store
1.什么是VUEX Vuex是管理vue的组件状态的工具. 个人理解:vuex是管理组件之间通信的一个插件. 2.为什么要用VUEX 我们知道组件之间是独立的,组件之间想要实现通信,我目前知道的就只有 ...
- axios模块封装
1.新建文件夹 network 在文件新建 request.js request.js: import axios from 'axios' export function request (conf ...
- 使用k8s容器钩子触发事件
原文: http://yunke.science/2018/04/15/k8s-hook/ 容器生命周期的钩子 Kubernetes为容器提供了生命周期钩子.钩子能使容器感知其生命周期内的事件,并且当 ...
- oracle中如何生成awr【性能调优】报告
1.进入数据库 sqlplus / as sysdba 2.查看用户 show parameter db_name 3.开始压测后执行 exec DBMS_WORKLOAD_REPOSITORY.CR ...
- Java 多线程编程——多线程
如果要想在Java之中实现多线程的定义,那么就需要有一个专门的线程主体类进行线程的执行任务的定义,而这个主体类的定义是有要求的,必须实现特定的接口或者继承特定的父类才可以完成. 1. 继承Thread ...
- English--比较结构
English|比较结构 接下来让我们一起来透析,英语中的比较结构.各位同学,带上小板凳,要认真哦~ 前言 目前所有的文章思想格式都是:知识+情感. 知识:对于所有的知识点的描述.力求不含任何的自我感 ...
- ANT 的使用
概述 ant 是一个将软件编译.测试.部署等步骤联系在一起加以自动化的一个工具,大多用于 Java 环境中的软件开发. 在与 Jmeter 生成的 jmx 文件配合使用中,ant 会完成jmx计划的执 ...