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 个题,解出 ...
随机推荐
- 线性回归(linear regression)
基本形式 最小二乘法估计拟合参数 最小二乘法:基于均方误差最小化来进行模型求解的方法称为“最小二乘法”(least square method) 即(左边代表 $\mathbf{\omega }$ 和 ...
- JQuery学习二-字典操作
1. 数组中添加map var arr = []; var key = 'Jeremy'; var value = '!!!!' arr.push({ 'key': key, 'value': val ...
- Linux 环境下jmeter 安装和配置
1. 下载和安装JDK vim /etc/profile export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_92 export JRE_HOME=$JAVA_HOME/jr ...
- 弹性盒式布局flexbox(dispaly:flex)
display:flex flex-direction: row(行)/column(列)/row-reverse/column-reverse反方向 //布局 justify-content: s ...
- hdu-1043 bfs+康拓展开hash
因为是计算还原成一种局面的最短步骤,应该想到从最终局面开始做bfs,把所有能到达的情况遍历一遍,把值存下来. bfs过程中,访问过的局面的记录是此题的关键,9*9的方格在计算过程中直接存储非常占内存. ...
- Flask之SQLAlchemy,flask_session以及蓝图
数据库操作 ORM ORM 全拼 Object-Relation Mapping,中文意为 对象-关系映射.主要实现模型对象到关系数据库数据的映射 优点 : 只需要面向对象编程, 不需要面向数据库编写 ...
- Crisp String CodeForces - 1117F (状压)
#include <iostream> #include <algorithm> #include <cstdio> #include <math.h> ...
- 『TensorFlow』TFR数据预处理探究以及框架搭建
一.TFRecord文件书写效率对比(单线程和多线程对比) 1.准备工作 # Author : Hellcat # Time : 18-1-15 ''' import os os.environ[&q ...
- 连手机logcat,出现read:unexpected EOF
使用logcat时,出现: 网上搜原因解释为log太多,普遍的解决方法是: adb logcat -G 20m 根本解决方法推荐:开发者设置,增大log size
- mstOne
云鸟(2017年6月6日) 1.html标签语义化的好处 a:利于seo优化 b:在样式丢失的时候,还是可以比较好的呈现结构 c:更好的支持各种终端,例如无障碍阅读和有声小说等. d:利于团队开发和维 ...