HDU3994(Folyd + 期望概率)
Mission Impossible
Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 227 Accepted Submission(s): 106
Special Judge
Missions Force) is a top secret spy organization in U.S. Ethan Hunt
have serviced in this organization for many years. Now, he is retired
and serves as a spy in a big company. Although he is very excellent, he
would make mistakes. For example, last time he invaded another company
to find some programming code. When he risked his life to steal the last
few pages of the code, he found that all of the letters on them are
only “}”. His boss is very angry. So, Ethan must finish this new mission
and he needs your help.
In
this new mission, Ethan successfully gets a big file in a computer and
decided to send this file from this computer to his boss’s computer
though the internet. We can assume the file is made of C small parts and
Ethan could only send one part each unit time.
The network
consists of n (n <= 200) computers, Ethan sits next to computer 1,
his boss sits next to computer 2. There exists a probability p[i][j]
between computer i and computer j, which means the probability of
successfully transferring each part from i to j is p[i][j]. However, all
of these links in the network are unidirectional (i.e. p[i][j] may be
different from p[j][i]). We defined the e[i][j] as the expected time to
send each part from i to j. For example, if p[i][j] = 10%, e[i][j] = 10
units.
You
may find that the probability would be very tiny and the expected time
could be very large since the route may be extremely long. Fortunately,
Ethan knows that he has m teammates sit next to several computers. He
can choose these computers as storage to shorten the transferring time.
(i.e. each of the n computers could be used as node
in any route, but only these m computers could be used as storages. Each
attempt to send a small part, successful or unsuccessful, takes
exactly one unite time, regardless of the number of links on the route.) So, he can do this mission as follows:
- Choose a computer which includes the file (i.e. C parts of information) as computer u.
- Choose
another computer his boss or some teammate sits next to as computer v,
and then takes time to transfer the file from u to v. If any part fails
to be transferred, it will be resent immediately.
- When the file is sent to his boss’s computer, the mission is finished.
To
satisfy his boss, Ethan must choose a route to make the total expected
time from computer 1(the computer near him) to computer 2(the computer
near his boss) minimum. You need to tell Ethan the minimum total
expected time.
It is an impossible mission aha? Why not have a try. It’s easier than expected.
In
each test case, you know n (2 <= n <= 200), which means the
number of computers. Then an n*n matrix p(n) is following. p[i][j] means
the probability of successfully transferring each part from i to j. You
may assume that 0 <= p[i][j] <= 100.
Next line contains m
(m <= n) means there are m computer that could serve as storage (i.e.
the number of computers near Ethan, his teammates or his boss). Then a
line contains m integer shows these computers. You may assume that it
must contains computer 1 and computer 2.
The last line tells you there C parts in the big file. C is an integer which insure the answer is less than 1 000 000 000.
each test case, you need to output a single line which contains the
minimum expected time of the transfer when Ethan chooses the best way to
finish his mission.
You’d better (not must) make the answer
rounded to 7 decimal places. Your answer would be considered correct if
each number has an absolute or relative error less than 10^-6.
5
0 1 20 0 0
0 0 0 0 0
0 0 0 50 90
0 20 0 0 0
0 0 0 90 0
3
1 2 5
10
4
0 100 0 0
100 0 100 0
0 100 0 100
0 0 100 0
0
1
1.000000
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
#define maxn 500
double p[maxn][maxn];
double temp[maxn][maxn];
int sto[maxn];
int n, m;
void folyd_probability()
{
for(int k = ; k <= n; k++)
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
{
if ((i==j) || (j==k) || (i==k)) continue;
p[i][j] = max(p[i][j], p[i][k]*p[k][j]);
}
}
void folyd_expect()
{
for(int k = ; k < m; k++)
for(int i = ; i < m; i++)
for(int j = ; j < m; j++)
{
if ((sto[i]==sto[j]) || (sto[j]==sto[k]) || (sto[i]==sto[k])) continue;
if (p[sto[i]][sto[k]]>= && p[sto[k]][sto[j]]>= && (p[sto[i]][sto[j]]< || p[sto[i]][sto[j]]>p[sto[i]][sto[k]]+p[sto[k]][sto[j]]))
{
p[sto[i]][sto[j]] = p[sto[i]][sto[k]] + p[sto[k]][sto[j]];
}
}
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d", &n);
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
{
scanf("%lf", &p[i][j]);
p[i][j] = p[i][j]/100.0;
}
folyd_probability(); scanf("%d", &m);
for(int i = ; i < m; i++)
scanf("%d", &sto[i]);
int i;
for(i = ; i < m; i++)
if(sto[i] == )
break;
if(i == m)
sto[m++] = ;
for(i = ; i < m; i++)
if(sto[i] == )
break;
if(i == m)
sto[m++] = ; for(i = ; i < m; i++)
for(int j = ; j < m ;j++)
{
temp[sto[i]][sto[j]] = p[sto[i]][sto[j]];
if(temp[sto[i]][sto[j]] < eps)
p[sto[i]][sto[j]] = -;
else
p[sto[i]][sto[j]] = 1.0/temp[sto[i]][sto[j]];
} folyd_expect();
int c;
scanf("%d", &c);
printf("%.6lf\n", p[][] * c);
}
return ;
}
HDU3994(Folyd + 期望概率)的更多相关文章
- HDU 3853 期望概率DP
期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] , 右移:[x][y ...
- 【BZOJ 3652】大新闻 数位dp+期望概率dp
并不难,只是和期望概率dp结合了一下.稍作推断就可以发现加密与不加密是两个互相独立的问题,这个时候我们分开算就好了.对于加密,我们按位统计和就好了;对于不加密,我们先假设所有数都找到了他能找到的最好的 ...
- 【BZOJ 3811】玛里苟斯 大力观察+期望概率dp+线性基
大力观察:I.从输出精准位数的约束来观察,一定会有猫腻,然后仔细想一想,就会发现输出的时候小数点后面不是.5就是没有 II.从最后答案小于2^63可以看出当k大于等于3的时候就可以直接搜索了 期望概率 ...
- 【BZOJ 3925】[Zjoi2015]地震后的幻想乡 期望概率dp+状态压缩+图论知识+组合数学
神™题........ 这道题的提示......(用本苣蒻并不会的积分积出来的)并没有 没有什么卵用 ,所以你发现没有那个东西并不会 不影响你做题 ,然后你就可以推断出来你要求的是我们最晚挑到第几大的 ...
- 【NOIP模拟赛】黑红树 期望概率dp
这是一道比较水的期望概率dp但是考场想歪了.......我们可以发现奇数一定是不能掉下来的,因为若奇数掉下来那么上一次偶数一定不会好好待着,那么我们考虑,一个点掉下来一定是有h/2-1个红(黑),h/ ...
- BZOJ2337: [HNOI2011]XOR和路径 期望概率dp 高斯
这个题让我认识到我以往对于图上期望概率的认识是不完整的,我之前只知道正着退还硬生生的AC做过的所有图,那么现在让我来说一下逆退,一般来说对于概率性的东西都只是正推,因为有了他爸爸才有了他,而对于期望性 ...
- BZOJ1415: [Noi2005]聪聪和可可 最短路 期望概率dp
首先这道题让我回忆了一下最短路算法,所以我在此做一个总结: 带权: Floyed:O(n3) SPFA:O(n+m),这是平均复杂度实际上为O(玄学) Dijkstra:O(n+2m),堆优化以后 因 ...
- 期望概率DP
期望概率DP 1419: Red is good Description 桌面上有\(R\)张红牌和\(B\)张黑牌,随机打乱顺序后放在桌面上,开始一张一张地翻牌,翻到红牌得到1美元,黑牌则付 ...
- LightOJ 1030 Discovering Gold(期望 概率)
正推,到达i的概率为p[i],要注意除了1和n外,到达i的概率并不一定为1 概率表达式为p[i] += p[j] / min(n - j, 6) 从j带过来的期望为exp[i] += exp[j] / ...
随机推荐
- poj 1149 pigs(最大流)
题目大意:迈克在农场工作,农场有 m 个猪舍,每个猪舍有若干只猪,但是迈克不能打开任何一间猪舍.有 n 个顾客前来购买,每个顾客有最大的购买数量,每个顾客可以购买某些猪舍的猪,且顾客可以打开这些猪舍, ...
- 第17讲- UI常用组件之ImageView图片浏览
第17讲 UI常用组件之ImageView图片浏览 二.图片浏览ImageView ImageView就是一个用来显示图片的视图: ImageView常见属性 常见属性 对应方法 说明 android ...
- 关于Latch
Latch是什么 Latch是SQL Server引擎保证内存中的结构的一致性的轻量同步机制.比如索引,数据页和内部结构(比如非叶级索引页).SQL Server使用Buffer Latch保护缓冲池 ...
- [RxJS] Reactive Programming - Why choose RxJS?
RxJS is super when dealing with the dynamic value. Let's see an example which not using RxJS: var a ...
- Error creating bean with name 'memcachedClient'...java.lang.OutOfMemoryError
1,Tomcat启动报错例如以下: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating ...
- 细讲encodeURI和encodeURIComponent以及escape的区别与应用
首先,我们都知道这三个东西都是用来编码的 先来说encodeURI()和encodeURIComponent() 这两个是在转换url时候用来编码解码用的. 有编码就会有解码, 解码就是decodeU ...
- 【转载】ADO.NET与ORM的比较(4):EntityFramework实现CRUD
[转载]ADO.NET与ORM的比较(4):EntityFramework实现CRUD 说明:个人感觉在Java领域大型开发都离不了ORM的身影,所谓的SSH就是Spring+Struts+Hiber ...
- Biztalk2010安装及配置问题集
在安装Biztalk2010时,碰到很多问题,有的是粗心有的也是比较bt的,如: 1)在win7 64下引入x86 的cab,有点粗心,幸亏给我报错版本不兼容(呵呵): 2)安装的时候 不知道为什么计 ...
- Byte、KB、MB、GB、TB、PB、EB是啥以及它们之间的进率
它们是存储单位 因为计算机存储单位一般用B,KB.MB.GB.TB.PB.EB.ZB.YB.BB来表示,它们之间的关系是: 位 bit (比特)(Binary Digits):存放一位二进制数,即 0 ...
- UVA 11754 Code Feat (枚举,中国剩余定理)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud C Code Feat The government hackers at C ...