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 个题,解出 ...
随机推荐
- QThread使用——关于run和movetoThread的区别
QThread 使用探讨 2010-10-23 00:30 注意:本文停止更新,请优先考虑 Qt 线程基础(QThread.QtConcurrent等) dbzhang800 2011.06.18 Q ...
- Flex外包公司——Flex案例展示
Flex案例展示 做的mail系统: http://gowebtop.com/webtop/ 在线购书网站 http://book.orzar.net/ eBay购物网站 http://www. ...
- Roslyn
Roslyn 是以 API 为驱动的下一代编译器,集成在最新版的 Visual Studio 上.它开放 C# 和 Visual Basic 编译器的 API,使得开发者可以借助编译器进行解析代码文件 ...
- SpringMVC使用Swagger
Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集成到服 ...
- Speak Confident English
I hope you don'd mind me asking... I know I shouldn't ask, but.... - Well, before I answer that ...
- ZZW原创_rsync同步时由于注释问题引起的@ERROR: chdir failed
1.需求:A机器同步文件到B机器 2.问题: A机器执行如下命令: [root@sv0379 rsync]# rsync -vzrtopg --password-file=/usr/local/rs ...
- python之模块定义、导入、优化详解
一.模块 1.模块的定义 模块是一组包含了一组功能的python文件,比如test.py,模块名为test,可以通过import test进行调用.模块可以分为以下四个通用类别 1 使用python编 ...
- Python连接mysql基本操作
创建数据库表 import pymysql # 打开数据库连接 db= pymysql.connect(host='localhost',user="root",password= ...
- java替换字符串中的World为Money
public class Money{ public static void main(String[] args) { String a = "Hello Java World\n&quo ...
- weinre 远程调试 安装 配置
1.第一种方法:安装:npm install -g weinre 2.第一种方法:开启本地监听服务器(修改端口,默认端口是8080):在cmd中运行: weinre --httpPort 8101 - ...