Bzoj1415: [Noi2005]聪聪和可可
2018-02-06 20:31
405 查看
题面
BzojSol
就是求期望预处理出可可在某一位置时聪聪下一步怎么走
然后按题意模拟,记搜
# include <bits/stdc++.h> # define RG register # define IL inline # define Fill(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long ll; const int _(2005); IL ll Input(){ RG ll x = 0, z = 1; RG char c = getchar(); for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1; for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); return x * z; } int n, m, fst[_], nxt[_], to[_], cnt, dis[_], pre[_][_], deg[_]; bool vis[_], G[_][_]; double f[_][_]; queue <int> Q; IL void Add(RG int u, RG int v){ to[cnt] = v; nxt[cnt] = fst[u]; fst[u] = cnt++; ++deg[v]; } IL void Bfs(RG int S){ dis[S] = 0; Fill(vis, 0); vis[S] = 1; Q.push(S); while(!Q.empty()){ RG int u = Q.front(); Q.pop(); for(RG int e = fst[u]; e != -1; e = nxt[e]){ if(vis[to[e]]) continue; dis[to[e]] = dis[u] + 1; vis[to[e]] = 1; Q.push(to[e]); } } for(RG int i = 1; i <= n; ++i) for(RG int e = fst[i]; e != -1; e = nxt[e]){ if(dis[to[e]] + 1 != dis[i]) continue; if(!pre[S][i]) pre[S][i] = to[e]; else pre[S][i] = min(pre[S][i], to[e]); } } IL double Dfs(RG int A, RG int B){ if(G[A][B]) return f[A][B]; G[A][B] = 1; RG int nt = pre[B][A]; if(A == B) return f[A][B] = 0; if(nt == B || pre[B][nt] == B) return f[A][B] = 1; nt = pre[B][nt]; f[A][B] = Dfs(nt, B); for(RG int e = fst[B]; e != -1; e = nxt[e]) f[A][B] += Dfs(nt, to[e]); f[A][B] = f[A][B] / (deg[B] + 1) + 1; return f[A][B]; } int main(RG int argc, RG char* argv[]){ n = Input(); m = Input(); Fill(fst, -1); RG int A = Input(), B = Input(); for(RG int i = 1; i <= m; ++i){ RG int u = Input(), v = Input(); Add(u, v); Add(v, u); } for(RG int i = 1; i <= n; ++i) Bfs(i); printf("%.3lf\n", Dfs(A, B)); return 0; }
相关文章推荐
- bzoj1415: [Noi2005]聪聪和可可 记忆化搜索
- bzoj 1415: [Noi2005]聪聪和可可 (概率与期望)
- BZOJ 1415 CODE[VS] 1784 [NOI2005 D2T2] 聪聪和可可
- 【NOI2005】bzoj1415 聪聪和可可
- bzoj 1415: [Noi2005]聪聪和可可【期望dp+bfs】
- [BZOJ]1415 [NOI2005] 聪聪与可可 期望 + 记忆化搜索
- BZOJ1415: [Noi2005]聪聪和可可
- 【bzoj1415】[Noi2005]聪聪和可可 期望记忆化搜索
- [BZOJ 1415][Noi2005]聪聪和可可:期望
- BZOJ 1415: [Noi2005]聪聪和可可( 最短路 + 期望dp )
- [bzoj1415][Noi2005]聪聪和可可
- BZOJ 1415 NOI2005 聪聪和可可 期望DP+记忆化搜索 BZOJ200题达成&&NOI2005全AC达成
- 【BZOJ1415】【NOI2005】聪聪和可可(动态规划,数学期望)
- [bzoj1415][NOI2005]聪聪与可可(期望+DP+Refun的胡策)
- 【BZOJ】1415 [Noi2005]聪聪和可可 期望DP+记忆化搜索
- bzoj1415[NOI2005]聪聪和可可-期望的线性性
- Bzoj1415: [Noi2005]聪聪和可可
- 【BZOJ1415】【NOI2005】聪聪和可可(动态规划,数学期望)
- bzoj 1415: [Noi2005]聪聪和可可
- BZOJ 1415: [Noi2005]聪聪和可可 [DP 概率]