HDU 5001 Walk (暴力、概率dp)
Walk
Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 266 Accepted Submission(s): 183 Special Judge
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.
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.
Your answer will be accepted if its absolute error doesn't exceed 1e-5.
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.6993317967
0.5864284952
0.4440860821
0.2275896991
0.4294074591
0.4851048742
0.4896018842
0.4525044250
0.3406567483
0.6421630037
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<string> #define N 55
#define M 15
#define mod 1000000007
#define p 10000007
#define mod2 100000000
#define ll long long
#define LL long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int T;
int n,m,d;
vector<int>bian[N];
int cnt[N];
double dp[][N];
double re; void ini()
{
int i;
int x,y;
memset(cnt,,sizeof(cnt));
scanf("%d%d%d",&n,&m,&d);
for(i=;i<=n;i++){
bian[i].clear();
}
while(m--){
scanf("%d%d",&x,&y);
bian[x].push_back(y);
bian[y].push_back(x);
}
for(i=;i<=n;i++){
cnt[i]=bian[i].size();
}
} void solve()
{
int q,o,i;
for(q=;q<=n;q++)
{
re=;
memset(dp,,sizeof(dp));
for(i=;i<=n;i++){
if(i==q) continue;
dp[][i]=1.0/n;
} for(o=;o<=d;o++){
for(i=;i<=n;i++){
if(i==q) continue;
for(vector<int>::iterator it=bian[i].begin();it!=bian[i].end();it++){
dp[o][i]+=dp[o-][*it]/cnt[*it];
}
}
} for(i=;i<=n;i++){
if(i==p) continue;
re+=dp[d][i];
}
printf("%.10f\n",re);
}
} void out()
{
//printf("%I64d\n",ans);
} int main()
{
//freopen("data.in","r",stdin);
scanf("%d",&T);
//for(int cnt=1;cnt<=T;cnt++)
while(T--)
//while(scanf("%I64d%I64d",&n,&m)!=EOF)
{
ini();
solve();
// out();
} return ;
}
HDU 5001 Walk (暴力、概率dp)的更多相关文章
- HDU - 5001 Walk(概率dp+记忆化搜索)
Walk I used to think I could be anything, but now I know that I couldn't do anything. So I started t ...
- HDU 4089 Activation(概率DP)(转)
11年北京现场赛的题目.概率DP. 公式化简起来比较困难....而且就算结果做出来了,没有考虑特殊情况照样会WA到死的.... 去参加区域赛一定要考虑到各种情况. 像概率dp,公式推出来就很容易写 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- HDU 5001 Walk
解题思路:这是一道简单的概率dp,只要处理好相关的细节就可以了. dp[d][i]表示走d步时走到i的改概率,具体参考代码: #include<cstdio> #include<cs ...
- Hdu 5001 Walk 概率dp
Walk Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5001 Desc ...
- HDU 4576 Robot (概率DP)
暴力DP求解太卡时间了...........写挫一点就跪了 //hdu robot #include <cstdio> #include <iostream> #include ...
- HDU 2955 Robberies 背包概率DP
A - Robberies Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 3366 Passage (概率DP)
Passage Problem Description Bill is a millionaire. But unfortunately he was trapped in a castle. The ...
- 2016ACM/ICPC亚洲区沈阳站H - Guessing the Dice Roll HDU - 5955 ac自动机+概率dp+高斯消元
http://acm.hdu.edu.cn/showproblem.php?pid=5955 题意:给你长度为l的n组数,每个数1-6,每次扔色子,问你每个串第一次被匹配的概率是多少 题解:先建成ac ...
随机推荐
- Vue 前端面试题[转]
https://mp.weixin.qq.com/s/Uxhx2dJ1Xbm6N3Gl7wNZNw Vue 前端面试题 游荡de蝌蚪 前端开发 1周前 作者:游荡de蝌蚪 https://segmen ...
- 项目中多条数据保存的json实例
//js代码function checkCode(num){ var typeid = $("#typeid").val(); if(typeid == "") ...
- HTML5拖放(drag和drog)作品
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- shell脚本,计算创建100个文件所用多少时间。
[root@localhost mulu]# ls [root@localhost mulu]# `; do touch file$i; done real 0m0.104s user 0m0.012 ...
- java在线聊天项目 使用SWT快速制作登录窗口,可视化窗口Design 更换窗口默认皮肤(切换Swing自带的几种皮肤如矩形带圆角)
SWT成功激活后 new一个JDialog 调整到Design视图 默认的视图模式是BorderLayout,无论你怎么拖拽,只能放到东西南北中的位置上 所以,我们把视图模式调整为AbsoluteLa ...
- CF-1082(渣渣只做了前三个)
链接:http://codeforces.com/contest/1082 A. Vasya and Book 题意: n,x,y,d 一本电子书有n页,每一次翻动只能往前或者往后翻d页.求x-> ...
- xadmin下设置“use_bootswatch = True”无效的解决办法
环境: python 2.7 django 1.9 xadmin采用源代码的方式引入到项目中 问题: 在xadmin使用的过程中,设置“use_bootswatch = True”,企图调出主题菜单, ...
- (30)zabbix Trapper 监控项配置
概述 zabbix获取数据有超时时间,如果一些数据需要执行比较长的时间才能获取的话,那么zabbix会出现异常,考虑到这种情况,zabbix增加了Trapper功能,客户端自己提交数据给zabbix, ...
- redis 散列学习要点记录
散列类型键值也是种字典结构,存储了字段和字段值的映射,字段值只能是字符串,不可以是其他类型(redis数据类型都不可嵌套使用其他类型),散列类型键可以有2的32次方减1个字段 散列的命令组 hset ...
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 F题
The Heaviest Non-decreasing Subsequence Problem 解题心得 这个题就是一个简单的动态规划,非递减最长子序列的改版(加一个权重),只要把权重为5的改成5个权 ...