标签:
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
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
///1085422276 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<queue> #include<cmath> #include<map> #include<bitset> #include<set> #include<vector> using namespace std ; typedef long long ll; #define mem(a) memset(a,0,sizeof(a)) #define TS printf("111111\n"); #define FOR(i,a,b) for( int i=a;i<=b;i++) #define FORJ(i,a,b) for(int i=a;i>=b;i--) #define READ(a,b) scanf("%d%d",&a,&b) #define mod 1000000007 #define inf 100000 #define maxn 300000 inline ll read() { ll 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*10+ch-‘0‘; ch=getchar(); } return x*f; } //****************************************************************** double dp[51][10005]; int n,m,D,vis[10005],jh; vector<int >G[500]; void dfs(int x,int d) { if(x==jh)return; int tmp=G[x].size(); for(int i=0;i<tmp;i++) { dp[G[x][i]][d]+=dp[x][d-1]/(tmp); } } int main() { int T=read(); while(T--) { n=read(),m=read(),D=read(); mem(dp); int a,b; FOR(i,1,n)G[i].clear(); FOR(i,1,m) { READ(a,b); G[a].push_back(b); G[b].push_back(a); } FOR(i,1,n){ mem(dp); jh=i; FOR(j,1,n) dp[j][0]=1.0/n; FOR(j,1,D) FOR(k,1,n)dfs(k,j); double ans=0.0; FOR(j,0,D)ans+=dp[i][j]; printf("%.10f\n",1-ans); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/zxhl/p/4782249.html