传送门

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的更多相关文章

  1. cf113D. Museum(期望 高斯消元)

    题意 题目链接 Sol 设\(f[i][j]\)表示Petya在\(i\),\(Vasya\)在\(j\)的概率,我们要求的是\(f[i][i]\) 直接列方程高斯消元即可,由于每个状态有两维,因此时 ...

  2. 【CF113D】Museum

    Portal --> cf113D Solution 额题意的话大概就是给一个无向图然后两个人给两个出发点,每个点每分钟有\(p[i]\)的概率停留,问这两个人在每个点相遇的概率是多少 如果说我 ...

  3. Solution -「CF113D」Museum

    Upd 2021.10.21 更改了状态定义. 记 \(S(u)\) 表示 \(u\) 结点的相邻结点的集合. 又记 \(p(u)\) 表示走到了 \(u\) 且下一步继续留在 \(u\) 结点的概率 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. [codeforces113D]Museum

    D. Museum time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input ...

  9. 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 ...

随机推荐

  1. IDEA rider 管道模式 经典模式(2)

    1.这里设置为Classic,并打开applicationhost.config将对应应用的 Clr4IntegratedAppPool全部替换为 Clr4ClassicAppPool 2.Confi ...

  2. service的yaml说明

    apiVersion: v1 kind: Service metadata: name: nginx-service labels: app: nginx spec: ports: - port: 8 ...

  3. ASP.NET Core 中的 Razor 文件编译

    asp .net core mvc 3.0 在编译的时候做了一些改变,有些view视图更改需要重新编译,你也可以配置运行时编译,不用每次更改都去重新生成,具体代码如下,从官方文档看到,做个记录. Ra ...

  4. 获取PostgreSQL数据库中得JSON值

    在PostgreSQL数据库中有一列为JSON,要获取JSON中得数据可以用下面sql: select orderno as OrderNo ,amount as Amount ,ordertime ...

  5. Python——数据分析,Numpy,Pandas,matplotlib

    由于图片内容太多,请拖动至新标签页再查看

  6. 解决:The web application [] registered the JDBC driver [] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

    问题描述 在将Spring Boot程序打包生成的war包部署到Tomcat后,启动Tomcat时总是报错,但是直接在IDEA中启动Application或者用"java -jar" ...

  7. Redis之缓存雪崩、缓存穿透、缓存预热、缓存更新、缓存降级

    目录 Redis之缓存雪崩.缓存穿透.缓存预热.缓存更新.缓存降级 1.缓存雪崩 2.缓存穿透 3.缓存预热 4.缓存更新 5.缓存降级 Redis之缓存雪崩.缓存穿透.缓存预热.缓存更新.缓存降级 ...

  8. c#打开颜色对话框

    用button时间 调出颜色对话框来: private void btnForeColor_Click(object sender, EventArgs e)        {            ...

  9. Android ListView显示不同样式的item

    先look图 我们再使用listview时,listview的item大多时候都是一种样式,在很多app中也很常见,但有时候根据需求,可能数据的数量不一样,同个类型的数据显示的位置不同,亦或者有的it ...

  10. 算法-memcopy与memmove的区别

    memcpy()和 memmove()都是C语言中的库函数,在头文件string.h中,作用是拷贝一定长度的内存的内容,原型如下 void *memcpy(void *dst, const void ...