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 ...
随机推荐
- mysql 存在更新,不存在插入
String sql = "insert into wb_result " + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ...
- python基础面试题整理---从零开始 每天十题(02)
书接上回,我们继续来说说python的面试题,我在各个网站搜集了一些,我给予你们一个推荐的答案,你们可以组织成自己的语言来说出来,让我们更好的做到面向工资编程 一.Q:说说你对zen of pytho ...
- Python基础篇 -- 小数据池和再谈编码
小数据池 1. id() 通过id()可以查看到一个变量表示的值在内存中的地址 s = "Agoni" print(id(s)) # 2410961093272 2. is 和 = ...
- Evaluate|GC content|Phred|BAC|heterozygous single nucleotide polymorphisms|estimate genome size|
(Evaluate):检查reads,可使用比对软件:使用SOAPaligner重新排列:采用massively parallel next-generation sequencing technol ...
- excel数据导入到数据库
package test; import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundExceptio ...
- OAuth授权之回调accessToken
具体说明见新浪官方文档 http://open.weibo.com/wiki/Oauth2/access_token 具体实现 第一步 打开回调页面 // 宏定义client_id #define ...
- Django项目部署:使用uwsgi和nginx的方式
一.背景 前两天制作的个人博客网站基本完工,大致功能具备.但是在部署环节却也处处碰壁,这里也来总结以下,以备将来不时查看以及完善. 二.前提 2.1 需要的知识 django Django是一个基于p ...
- mysql存储过程详解及基于PHP使用实例
mysql存储过程详解 1. 存储过程简介 我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的S ...
- day12-图
- URI URL URN 关系
我们一起来看下面这个虚构的例子.这是一个URI: http://bitpoetry.io/posts/hello.html#intro 我们开始分析 http:// 是定义如何访问资源的方式.另外 b ...