HDU 5001 概率dp
2015-09-04 19:58
369 查看
Walk
Time Limit : 30000/15000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other)Special Judge
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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.
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.
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.
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
Source
2014 ACM/ICPC Asia Regional Anshan Online题意:给你一个无向图,可以从任意点出发问你走d步的特定下,这n个点分别不能经过的概率
上代码:
///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; }
代码
相关文章推荐
- Hadoop开篇之Mapreduce实现多类别流量统计的两种实现方式
- 螺旋矩阵 有内及外 逆时针
- Jquery ui Interactions方法的使用实例
- hdoj 1042 N! 【大数阶乘】
- CCF 201312-4 有趣的数 (数位DP)
- sass、less和stylus的安装使用和入门实践
- AWR 分析
- 剑指offer:数值的整数次方 代码实现
- Calculus on Computational Graphs: Backpropagation
- Java transient关键字使用笔记
- ENGINX--简单篇
- hdu~4707(vector)
- 基本数据类型的转换
- Lock和synchronized
- 机器学习实战
- iOS 网易彩票-3常见设置
- iptables + Denyhost抵御暴力破解
- Kinect v2.0原理介绍之七:彩色帧获取
- Machine Learning Trick of the Day (2): Gaussian Integral Trick
- HDU 3652 B-number