#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;
#define N 1020
int n;
double p[N][N];
double m[N], A[N], B[N];
bool vis[N];
int dcmp(double x) {
if(fabs(x) < 1e-12) return 0;
return x < 0? -1: 1;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
scanf("%lf", &p[i][j]);
p[i][j] /= 100;
}
}
for(int i = 1; i <= n; ++i) A[i] = B[i] = 1, m[i] = 1e30;
m[n] = 0;
for(int i = 1; i <= n; ++i) {
int u = -1;
double tmp = 1e10;
for(int j = 1; j <= n; ++j) {
if(m[j] < tmp && !vis[j]) tmp = m[j], u = j;
}
vis[u] = 1;
for(int x = 1; x <= n; ++x) {
if(vis[x]) continue;
B[x] += A[x] * p[x][u] * m[u];
A[x] *= 1 - p[x][u];
}
for(int x = 1; x <= n; ++x) {
if(vis[x]) continue;
if(dcmp(1 - A[x]) == 0) m[x] = 1e30;
else
m[x] = B[x] / (1 - A[x]);
}
}
printf("%.12lf\n", m[1]);
return 0;
}
CodeForces 605E Intergalaxy Trips (概率)
最新推荐文章于 2021-02-17 20:02:44 发布