HDU-5001 Walk (概率DP)
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.
# 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;
}
HDU-5001 Walk (概率DP)的更多相关文章
- Hdu 5001 Walk 概率dp
Walk Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5001 Desc ...
- 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 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
- HDU - 1099 - Lottery - 概率dp
http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...
- HDU 4405 【概率dp】
题意: 飞行棋,从0出发要求到n或者大于n的步数的期望.每一步可以投一下筛子,前进相应的步数,筛子是常见的6面筛子. 但是有些地方可以从a飞到大于a的b,并且保证每个a只能对应一个b,而且可以连续飞, ...
- HDU 4576 Robot(概率dp)
题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...
- HDU 5001 Walk
解题思路:这是一道简单的概率dp,只要处理好相关的细节就可以了. dp[d][i]表示走d步时走到i的改概率,具体参考代码: #include<cstdio> #include<cs ...
- HDU 4599 Dice (概率DP+数学+快速幂)
题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...
- [HDU 4089]Activation[概率DP]
题意: 有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有以下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排在队列的最后( ...
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
随机推荐
- 谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数。
谷歌笔试题--给定一个集合A=[0,1,3,8](该集合中的元素都是在0,9之间的数字,但未必全部包含), 指定任意一个正整数K,请用A中的元素组成一个大于K的最小正整数. Google2009华南地 ...
- c++第十五天
<c++ primer, 5E> 第94页到第99页,笔记: 1.迭代器(iterator):一种比下标访问更通用的访问容器中元素的机制. (并不是所有标准库容器都支持下标访问,<运 ...
- SNMP学习笔记之Linux服务器SNMP常用OID
收集整理一些Linux下snmp常用的OID,用做服务器监控很不错. 应用示例 查看服务器1分钟平均负载: snmpwalk -v1 -c public 127.0.0.1 .1.3.6.1.4.1. ...
- 20145101《Java程序设计》第10周学习总结
20145101<Java程序设计>第10周学习总结 教材学习内容总结 网络编程 网络编程的实质就是两个(或多个)设备(例如计算机)之间的数据传输. 计算机网络 路由器和交换机组成了核心的 ...
- warning C4018: “<”: 有符号/无符号不匹配
原因: 将两个不同的类型进行了比较,如: int a:unsigned short b: if(a>b)... 解决:改为同一种类型
- JS控制页面内容
JS操作页面内容 innerText:普通标签内容(自身文本与所有子标签文本)innerHTML:包含标签在内的内容(自身文本及子标签的所有)value:表单标签的内容outerHTML:包含自身标签 ...
- LightOJ - 1247 Matrix Game (Nim博弈)题解
题意: 给一个矩阵,每一次一个玩家可以从任意一行中选任意数量的格子并从中拿石头(但最后总数要大于等于1),问你谁赢 思路: 一开始以为只能一行拿一个... 将每一行石子数相加就转化为经典的Nim博弈 ...
- bootstrap栅格系统进行偏移格式
本文为博主原创,转载请注明出处: offset偏移都是向右偏移,且只能向右偏移,例: col-md-offset-2,向右偏移两列. col-md-pull-偏移数值 //向左偏移 c ...
- jdk、tomcat、solr环境搭建
环境概述 1)操作系统:windows7旗舰版(64位) 2)jdk:jdk-8u131-windows-x64: 3)tomcat:apache-tomcat-9.0.0.M21 4)solr:so ...
- c++ 判断数组元素是否有负数(any_of)
#include <iostream> // std::cout #include <algorithm> // std::any_of #include <array& ...