标签:
# include<iostream> # include<cstdio> # include<vector> # include<cstring> # include<algorithm> using namespace std; vector<int>v[55]; int n,m,d,vis[10005][55]; double dp[10005][55]; void solve() { for(int i=1;i<=n;++i){ memset(dp,0,sizeof(dp)); for(int j=1;j<=n;++j) dp[0][j]=1.0/n; for(int j=1;j<=d;++j){ for(int start=1;start<=n;++start){ if(i==start) continue; int l=v[start].size(); for(int k=0;k<l;++k) dp[j][v[start][k]]+=dp[j-1][start]*1.0/l; } } double ans=0.0; for(int j=1;j<=n;++j) if(j!=i) ans+=dp[d][j]; printf("%.10lf\n",ans); } } int main() { int T,a,b; vector<int>::iterator it; scanf("%d",&T); while(T--) { memset(vis,0,sizeof(vis)); scanf("%d%d%d",&n,&m,&d); for(int i=1;i<=n;++i) v[i].clear(); while(m--) { scanf("%d%d",&a,&b); it=find(v[a].begin(),v[a].end(),b); if(it==v[a].end()) v[a].push_back(b); it=find(v[b].begin(),v[b].end(),a); if(it==v[b].end()) v[b].push_back(a); } solve(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/20143605--pcx/p/4800681.html