hdu5001 Walk 概率DP
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.
题意:有一张双连通图,有个人在图上等概率随机选择起点,每一步等概率随机选择下一个走的点,一共走 d 步,问每个点没有被走到的概率是多少。
组数20,点数50,边数2450,总步数10000,暴力更新复杂度 20 × 50 × 2450 × 10000,重点:时限15秒!
随便暴……
dp [ i ] [ j ] [ k ] 表示当前第 i 轮,正位于 j 点,途中没有经过 k 点的概率总和。
每一轮在 j 点确定下一个点走哪个点时,其概率都可以累加到没有走到其他点的概率上。
数组开不下用滚动。
#include<stdio.h>
#include<string.h> int head[],nxt[],point[],size;
int num[];
double a[][][],ans[];
//int ma[55][55] void add(int a,int b){
point[size]=b;
nxt[size]=head[a];
head[a]=size++;
num[a]++;
point[size]=a;
nxt[size]=head[b];
head[b]=size++;
num[b]++;
} int main(){
int T;
scanf("%d",&T);
while(T--){
int n,m,d;
scanf("%d%d%d",&n,&m,&d);
memset(head,-,sizeof(head));
size=;
memset(num,,sizeof(num));
while(m--){
int u,v;
scanf("%d%d",&u,&v);
add(u,v);
// ma[u][v]=ma[v][u]=1;
}
for(int i=;i<=n;++i){
for(int j=;j<=n;++j){
if(i!=j)a[][i][j]=1.0/n;
else a[][i][j]=;
}
}
int o=;
// if(d>1000)d=1000;
for(int i=;i<=d;++i){
memset(a[o^],,sizeof(a[o^]));
for(int j=;j<=n;++j){
for(int u=head[j];~u;u=nxt[u]){
int v=point[u];
for(int k=;k<=n;++k){
if(j!=k)a[o^][j][k]+=a[o][v][k]/num[v];
}
}
}
o^=;
}
for(int i=;i<=n;++i){
ans[i]=;
for(int j=;j<=n;++j)ans[i]+=a[o][j][i];
}
for(int i=;i<=n;++i)printf("%.10lf\n",ans[i]);
}
return ;
}
hdu5001 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 4579 Random Walk 概率DP
思路:由于m非常小,只有5.所以用dp[i]表示从位置i出发到达n的期望步数. 那么dp[n] = 0 dp[i] = sigma(dp[i + j] * p (i , i + j)) + 1 . ...
- hdu5001(概率dp)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5001 题意:一个人随即从一个点出发,到达邻接点的概率相同,求出走d步都不会到达1~n点的每一点i的概率 ...
- 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 ...
- [Poj3744]Scout YYF I (概率dp + 矩阵乘法)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9552 Accepted: 2793 Descr ...
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- POJ 2096 Collecting Bugs (概率DP)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- POJ 2151 Check the difficulty of problems (概率DP)
题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...
随机推荐
- Mac OS X 避免产生临时文件 .DS_Store
参考: 删除Mac中所有 .DS_Store 隐藏文件 Mac OS X 避免产生临时文件 .DS_Store .DS_Store 隐藏文件保存针对目录的特殊信息和设置配置,例如查看方式,图标大小以及 ...
- TeXstudio+TexLive交叉引用
LaTeX 交叉引用系统简介 https://www.cnblogs.com/wenbosheng/p/9537774.html 一般来说需要两次运行排版命令才能生成引用编号.背后的原理是这样的,第一 ...
- java笔记 -- 数学函数与常量
Math类中, 包含了各种数学函数 不用在数学方法名和常量名前添加前缀Math., 只要在源文件的顶部加上这行代码: import static java.lang.Math.*; (静态导入) 例: ...
- C#退出程序方法分类
1.this.Close(); 只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出:
- ubuntu1404安装搜狗输入法
1.安装fcitx,一种输入法框架 apt-get install fcitx 2.配置使用fcitx 配置中心-语言支持-键盘输入方式系统,选择fcitx 3.登出再登入 4.下载sougou安装d ...
- 基于Bootsrap的BeyondAdmin前端模板 --分享
1.PC端 2.移动端 3.下载 最新:http://www.yidt.cn/ 链接:https://pan.baidu.com/s/1Tx6EVmGFnVV7H7h3SFwldA 提取码:0btw
- 『流畅的Python』第12章:继承的优缺点
- STL 小白学习(5) stack栈
#include <iostream> #include <stack> //stack 不遍历 不支持随机访问 必须pop出去 才能进行访问 using namespace ...
- python全局变量
定义函数里面的叫局部变量,出了函数外面就不能用了 局部变量函数被调用时,他的变量才生效 局部变量定义在内存里面,用完就会被释放,全局变量不会释放 当有相同名的局部变量和全局变量,函数会先找自己的变量, ...
- Forth 采用Create,Does>定义新的词(word)& 延迟词技术
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...