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 ...
随机推荐
- JMeter:全面的乱码解决方案
中文乱码一直都是比较让人棘手的问题,我们在使用Jmeter的过程中,也会遇到中文乱码问题 接口:http://127.0.0.1:8090/test 这个接口有一个参数name,返回结果就是你传的na ...
- Struts2 Spring Hibernate 框架整合 Annotation MavenProject
项目结构目录 pom.xml 添加和管理jar包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...
- PT100高精度测温电路 AD623+REF3030(转)
源: PT100高精度测温电路 AD623+REF3030(很稳定)
- python3 isinstance()判断元素是否是字符串、int型、float型
python3 isinstance()判断元素是否是字符串.int型.float型 isinstance是Python中的一个内建函数 语法: isinstance(object, classinf ...
- nginx配置https并强制http自动跳转到https
关于使用HTTPS/SSL的必要性,可以自行baidu,援引的说法,EFF(Electronic Frontier Foundation),全球过半流量采用https. https://www.osc ...
- 20145317彭垚 MSF基础应用
20145317彭垚 MSF基础应用 基础问题回答 用自己的话解释什么是exploit,payload,encode? exploit就相当于是载具,将真正要负责攻击的代码传送到靶机中,我觉得老师上课 ...
- 20145330 《网络对抗》 Web安全基础实践
20145330 <网络对抗> Web安全基础实践 1.实验后回答问题 (1)SQL注入攻击原理,如何防御 SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字 ...
- 从一道题看线程安全--牛客网Java基础题
从一道题看线程安全 Java中的线程安全是什么: 就是线程同步的意思,就是当一个程序对一个线程安全的方法或者语句进行访问的时候,其他的不能再对他进行操作了,必须等到这次访问结束以后才能对这个线程安全的 ...
- Spring Aop的理解和简单实现
1.AOP概念 所说的面向切面编程其实就是在处理一系列业务逻辑的时候这一系列动作看成一个动作集合.比如连接数据库来说: 加载驱动-----获取class--------获取连接对象-------访问数 ...
- div转svg svg转canvas svg生成图片及图片下载 分享
链接来自:http://blog.csdn.net/u010081689/article/details/50728854