[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 ...
随机推荐
- solr常见错误
这两天给客户部署独立的solr服务器遇到的错误,现在总结一下. 1. org.apache.solr.client.solrj.SolrServerException: Error executing ...
- https的原理入门
现在基本上互联网上访问的地址都是使用HTTPS协议了,只有局域网才会使用HTTP协议,因此了解HTTPS十分重要. HTTP存在的问题 上过网的朋友都知道,网络是非常不安全的.尤其是公共场所有很多免费 ...
- 【转】.Net程序员学习Linux最简单的方法
有很多关于Linux的书籍.博客.大多数都会比较“粗暴“的将一大堆的命令塞给读者,从而使很多.NET程序员望而却步.未入其门就路过了. 所以我设想用一种更为平滑的学习方式, 就是在学习命令时,先用纯语 ...
- 让你的 vs code 跑在云上,用手机浏览器就能写代码
让你的vs code 跑在云服务器上 在B站上看到一个视频Run VS Code in the browser with massive computing resources(教你如何配置一个云ID ...
- 自己对Thread的一些看法;
Thread thread= new Thread(new ThreadStart(name); 与 Thread thread= new Thread(name); thread.star( ...
- 正则表达式(RegEx)官方手册/权威指南【Python】
前言 正则表达式(称为RE,或正则,或正则表达式模式)本质上是嵌入在Python中的一种微小的.高度专业化的编程语言,可通过 re 模块获得. 使用这种小语言,你可以为要匹配的可能字符串集指定规则:此 ...
- 基于Golang的逃逸分析(Language Mechanics On Escape Analysis)
何为逃逸分析 在编译程序优化理论中,逃逸分析是一种确定指针动态范围的方法——分析在程序的哪些地方可以访问到指针.它涉及到指针分析和形状分析. 当一个变量(或对象)在子程序中被分配时,一个指向变量的指针 ...
- Ipfs基础入门
Ipfs介绍 Ipfs(Inter-Planetary File System!),中文译为星际网络文件系统,是基于默克尔有向无环图(merkle dag)的全球性p2p文件系统. 是一个面向全球的, ...
- xss学习
1.了解xss的定义 2.理解xss的原理:反射型和存储型 3.理解xss的攻击方式 4.掌握xss的防御措施
- 安装MySQL-8.0.13
安装1.去官网下载对应的MySQL版本http://downloads.mysql.com/archives/community/ 2.将下载下来的MySQL解压到你想要安装的目录下安装MySQL8. ...