2014鞍山網路賽 E題||hdu 5001 概率dp
http://acm.hdu.edu.cn/showproblem.php?pid=5001
Problem Description
I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling.
The nation looks like a connected bidirectional graph, and I am randomly walking on it. It means when I am at node i, I will travel to an adjacent node with the same probability in the next step. I will pick up the start node randomly (each node in the graph has the same probability.), and travel for d steps, noting that I may go through some nodes multiple times.
If I miss some sights at a node, it will make me unhappy. So I wonder for each node, what is the probability that my path doesn't contain it.
The nation looks like a connected bidirectional graph, and I am randomly walking on it. It means when I am at node i, I will travel to an adjacent node with the same probability in the next step. I will pick up the start node randomly (each node in the graph has the same probability.), and travel for d steps, noting that I may go through some nodes multiple times.
If I miss some sights at a node, it will make me unhappy. So I wonder for each node, what is the probability that my path doesn't contain it.
Input
The first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains 3 integers n, m and d, denoting the number of vertices, the number of edges and the number of steps respectively. Then m lines follows, each containing two integers a and b, denoting there is an edge between node a and node b.
T<=20, n<=50, n-1<=m<=n*(n-1)/2, 1<=d<=10000. There is no self-loops or multiple edges in the graph, and the graph is connected. The nodes are indexed from 1.
For each test case, the first line contains 3 integers n, m and d, denoting the number of vertices, the number of edges and the number of steps respectively. Then m lines follows, each containing two integers a and b, denoting there is an edge between node a and node b.
T<=20, n<=50, n-1<=m<=n*(n-1)/2, 1<=d<=10000. There is no self-loops or multiple edges in the graph, and the graph is connected. The nodes are indexed from 1.
Output
For each test cases, output n lines, the i-th line containing the desired probability for the i-th node.
Your answer will be accepted if its absolute error doesn't exceed 1e-5.
Your answer will be accepted if its absolute error doesn't exceed 1e-5.
Sample Input
2
5 10 100
1 2
2 3
3 4
4 5
1 5
2 4
3 5
2 5
1 4
1 3
10 10 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
4 9
Sample Output
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.6993317967
0.5864284952
0.4440860821
0.2275896991
0.4294074591
0.4851048742
0.4896018842
0.4525044250
0.3406567483
0.6421630037
解題思路: dp[i][j][k]表示,i代表當前 第i步,j代表當前走到第j個節點,k是沒有路過k,整體是 走到第i步恰好在j節點,這個過程中沒有路過k的概率
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
double a[3][55][55],ans[55];
int mp[55][55],cnt[55];
int T,n,m,d;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&d);
memset(mp,0,sizeof(mp));
memset(a,0,sizeof(a));
memset(cnt,0,sizeof(cnt));
for(int i=0; i<m; i++)
{
int u,v;
scanf("%d%d",&u,&v);
mp[u][v]=mp[v][u]=1;
cnt[u]++;
cnt[v]++;
}
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if(i!=j)
a[1][i][j]=1.0/n;
else
a[1][i][j]=0;
for(int i=1; i<=d; i++)
{
memset(a[(i+1)%2],0,sizeof(a[(i+1)%2]));
for(int j=1; j<=n; j++)
for(int k=1; k<=n; k++)
if(mp[j][k])
for(int p=1; p<=n; p++)
if(k!=p)
a[(i+1)%2][k][p]+=a[i%2][j][p]*(1.0/cnt[j]);
else
a[(i+1)%2][k][p]=0;
}
for(int i=1;i<=n;i++)
{
ans[i]=0;
for(int j=1;j<=n;j++)
ans[i]+=a[(d+1)%2][j][i];
}
for(int i=1;i<=n;i++)
printf("%.10lf\n",ans[i]);
}
return 0;
}
相關文章
- HDU 5816 Hearthstone(狀態壓縮DP+概率)
- ACM-ICPC 2018 南京賽區網路預賽__E AC Challenge【狀態壓縮+DP】ACM
- hdu--4455+ Substrings+2012杭州區域賽C題+DP
- 洛谷 P4284 [SHOI2014]概率充電器 概率與期望+換根DP
- hdu 2111 Saving HDU (DP)
- hdu 6415 - DP
- 2020 ICPC 線上模擬賽 E題 Eat Walnuts(區間dp)
- HDU 6787 Chess 2020百度之星 初賽三 T5 題解 dp
- HDU6415(DP)
- HDU1024(dp)
- POJ 3071 Football(概率DP)
- HDU 6415 (計數dp)
- [DP]HDU6415(2018多校訓練賽第九場 Problem A) Rikka with Nash Equilibrium 題解UI
- 【訓練題19:概率DP】One Person Game | ZOJ3329GAM
- HDU 6415 Rikka with Nash Equilibrium (DP)UI
- luogu P6835 概率DP 期望
- 鞍山哪裡有開票-鞍山開票
- HDU6415:Rikka with Nash Equilibrium(dp)UI
- HDU 6035 Colorful Tree(樹形DP)
- HDU 1074 Doing Homework(狀壓DP)
- 2018 徐州網路賽 G 題解
- 2024ccpc網路賽補題
- HDU 6415(dp/記憶化搜尋)
- HDU4652 Dice(期望dp推式子)
- 2014中國網路效能報告
- bzoj3675: [Apio2014]序列分割(Dp)API
- bzoj3875: [Ahoi2014&Jsoi2014]騎士遊戲(spfa+Dp)JS遊戲
- 牛客練習賽74 E CCA的期望(算概率的技巧+floyd處理)
- CF1851E. Nastya and Potions 題解 DAG上的DPAST
- [狀壓dp] 最短Hamilton路徑(模板題+狀壓dp)
- 狀壓 + 網路流 -- Escape HDU - 3605
- HDU多校第九次 6415 (dp
- ACM-ICPC 2018 南京賽區網路預賽__K The Great Nim Game【博弈論+費馬小定理+DP】ACMGAM
- cf314E. Sereja and Squares(dp)
- HDU-6415 Rikka with Nash Equilibrium (DP/找規律)UI
- 【演算法學習筆記】概率與期望DP演算法筆記
- [kuangbin帶你飛]專題十二 基礎DP1 D - Doing Homework HDU - 1074
- AtCoder Beginner Contest 370 E(計數 + DP)
- 「暑期訓練」「基礎DP」 Monkey and Banana (HDU-1069)NaN