给你一个连通的无向图,等概率随机选取一个起点,走d步,每一步等概率走到相邻的点。问走完d步之后,每个点没有被经过的概率。

推状态的关键当然就是对这个“从任意起点走完d步点node没被经过的概率”的理解了,转一下方向,这句话的意思其实等价于“我避开点node走d步到达其它点的概率之和”;

设状态方程p[node][d][i]为避开node走d步到达i点的概率,那么Σp[node][n][i],(i=1~n)即“从任意起点走完d步点node没被经过的概率”

初始时每个点的状态相当于走0步到达该点的状态,即p[node][0][i] = 1.0/n,(i != node);

之后,走d步到达i点的概率等价于走d-1步到达与i邻接的点g[i][j]的概率和,(g[i][j] != node);

根据以上分析求解就很容易了。因为是分别求点所以可以把数组第一维省略掉节省内存。

主要代码:

 void dp()
{
for(int i = ; i <= n; i++) p[][i] = 1.0/n;
for(int node = ; node <= n; node++)
{
for(int d = ; d <= k; d++)
for(int i = ; i <= n; i++)
p[d][i] = ; for(int d = ; d <= k; d++)
for(int i = ; i <= n; i++)
{
if(i == node) continue ;
double sum = 0.0;
int sz = g[i].size();
if(sz == ) continue;
for(int j = ; j < g[i].size(); j++)
{
if(g[i][j] == node) { continue ;}
sum += p[d-][g[i][j]];
}
p[d][i] = sum/(sz);
}
double ans = 0.0;
for(int i = ; i <= n; i++)
{
ans += p[k][i];
}
printf("%.10lf\n", ans);
}
}

hdu 5001

【概率dp,难度3颗星】hdu-5001(2014鞍山网络赛)的更多相关文章

  1. hdu 5071(2014鞍山现场赛B题,大模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...

  2. hdu 5078 2014鞍山现场赛 水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,由于说了ti<ti+1 //#pragma comment(link ...

  3. hdu 5078(2014鞍山现场赛 I题)

    数据 表示每次到达某个位置的坐标和时间 计算出每对相邻点之间转移的速度(两点间距离距离/相隔时间) 输出最大值 Sample Input252 1 9//t x y3 7 25 9 06 6 37 6 ...

  4. ZOJ 3822 Domination 概率dp 难度:0

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  5. HDU 4089 Activation 概率DP 难度:3

    http://acm.hdu.edu.cn/showproblem.php?pid=4089 这道题中一共有两个循环: 1.事件1 如果一直落在Activation failed事件上,那么就会重新继 ...

  6. HDU 4050 wolf5x 概率dp 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4050 题意: 现在主角站在0处,需要到达大于n的位置 主角要进入的格子有三种状态: 0. 不能进入 1. 能进入 ...

  7. HDU 4405 Aeroplane chess 概率DP 难度:0

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...

  8. CF 148D Bag of mice 概率dp 难度:0

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  9. HDU 6199 2017沈阳网络赛 DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6199 题意:n堆石子,Alice和Bob来做游戏,一个人选择取K堆那么另外一个人就必须取k堆或者k+1 ...

随机推荐

  1. Spring Autowiring by Constructor

    In Spring, "Autowiring by Constructor" is actually autowiring by Type in constructor argum ...

  2. hdu 4496 (并差集)

    题意:给出一个图,m条边,输出删除前i条边后该图的联通块的个数. 思路:刚开始想着是不是联通问题,后来看明白题意后知道,如果从最后一条边添加的话,答案就会出来了,就是并差集的操作. #include& ...

  3. 连接查询中on and和on where的区别

    一.区别 1. and条件是在生成临时表时使用的条件,它不管and中的条件是否为真,都会返回左(或者右)边表中的记录. 2.where条件是在临时表生成好后,再对临时表进行过滤的条件.这时已经没有le ...

  4. shiro安全框架

    原文:http://blog.csdn.net/boonya/article/details/8233303 可能大家早先会见过 J-security,这个是 Shiro 的前身.在 2009 年 3 ...

  5. js奇葩错误

    局部刷新中显示图片: 错误写法:var innerDiv = "<p class='town_con' id='city1'>";              var d ...

  6. Python3学习

    要做一个儿童搜索引擎的项目(www.kidsearch.cn),所以开始接触各种新的语言,初步学了PHP爬虫,觉得要做大点的项目用PHP确实不太方便,中文兼容性就是一个比较棘手的问题.python的爬 ...

  7. VHD_Update_mount-vhd

    ###################功能说明########################该脚本用来对离线VHD文件更新,导入系统补丁############################### ...

  8. PS-常用操作

    快捷键 设置图片的大小:ctrl+t 放大缩小:ctrl+空格+“+or-”

  9. Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集

    D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...

  10. Codeforces Gym 100733H Designation in the Mafia flyod

    Designation in the MafiaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...