Walk

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.

InputThe 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.OutputFor 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 第一道比赛出的概率dp。找好状态记忆化搜索即可。
#include<bits/stdc++.h>
#define MAX 55
using namespace std;
typedef long long ll; int n,m,k;
double ans;
double dp[MAX][];
vector<int> v[MAX];
double dfs(int f,int x,int s){
int i;
if(s>=k) return ;
if(dp[x][s]>-) return dp[x][s];
int xx=v[x].size();
double cnt=;
for(i=;i<v[x].size();i++){
if(v[x][i]==f) continue;
cnt+=dfs(f,v[x][i],s+)*(1.0/xx);
}
dp[x][s]=cnt;
return cnt;
}
int main()
{
int t,i,j;
int x,y;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&k);
for(i=;i<=n;i++){
v[i].clear();
}
for(i=;i<=m;i++){
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
for(i=;i<=n;i++){
ans=;
memset(dp,-,sizeof(dp));
for(j=;j<=n;j++){
if(i==j) continue;
ans+=dfs(i,j,)*(1.0/n);
}
printf("%.10f\n",ans);
}
}
return ;
}

最新文章

  1. JAVA 多线程随笔 (三) 多线程用到的并发容器 (ConcurrentHashMap,CopyOnWriteArrayList, CopyOnWriteArraySet)
  2. C++ REST SDK的基本用法
  3. linux 文件系统解析及相关命令
  4. iptables下state的4种形式
  5. 字符设备 register_chrdev_region()、alloc_chrdev_region() 和 register_chrdev() (转载)
  6. C语言输出规定长度的整数,不够位数前面补零
  7. OpenMp之sections用法
  8. yii2单独给input或者其他标签定义class
  9. Android中的缓存机制与实现
  10. 破解SharpPlus Sqlite Develope[转]
  11. Akka(6): become/unbecome:运算行为切换
  12. re+正则01
  13. 【Web前端】用CSS3实现弹幕
  14. Binary Logging Formats
  15. canvas 实现飞碟射击游戏
  16. sql随机抽取数据
  17. java web 程序---缓冲代码
  18. Java虚拟机 - 符号引用和直接引用理解
  19. [GO]数组指针做函数参数
  20. js原形链

热门文章

  1. mysql系列之7.mysql读写分离
  2. iOS 流布局 UICollectionView使用(使用FlowLayout进行更灵活布局)
  3. JavaScript 如何创建search字段
  4. Java for LeetCode 124 Binary Tree Maximum Path Sum
  5. Django的模型层(2)---多表操作
  6. (C)位字段(bit-field)
  7. vue 动态传值笔记
  8. POJ3415 Common Substrings —— 后缀数组 + 单调栈 公共子串个数
  9. AOP和IOC的作用(转)
  10. 详解C/C++ 编译 g++ gcc 的区别