#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int MAXN = 35;
const double INF = 0x3f3f3f3f*1.0;
int n, m, p, a, b;
int ticket[MAXN], d[MAXN][MAXN];
int main()
{
double **dp;
while(cin >> n >> m >> p >> a >> b)
{
if(!(n || m || p || a || b))
return 0;
for(int i = 0; i < n; i++)
scanf("%d", &ticket[i]);
dp = (double **)malloc(sizeof(double *)*((1<<n)-1));
for(int i = 0; i < 1 << n; i++)
{
dp[i] = (double *)malloc(sizeof(double)*m);
fill(dp[i], dp[i] + m, INF);
}
dp[(1<<n)-1][a - 1] = 0;
memset(d, -1, sizeof(d));
double res = INF;
for(int i = 0; i < p; i++)
{
int s, e, num;
scanf("%d%d%d", &s, &e, &num);
d[s-1][e-1] = d[e-1][s-1] = num;
}
for(int s = (1<<n)-1; s >= 0; s--)
{
res = min(res, dp[s][b-1]);
for(int v = 0; v < m; v++)
{
for(int i = 0; i < n; i++)
{
if(s >> i & 1)
{
for(int u = 0; u < m; u++)
if(d[v][u] >= 0)
{
dp[s & ~(1<<i)][u] = min(dp[s & ~(1<<i)][u], dp[s][v] + (double)d[v][u] / ticket[i]);
}
}
}
}
}
if(res == INF)
cout << "Impossible\n";
else
printf("%.3f\n", res);
}
return 0;
}
poj2686Traveling by Stagecoach状态压缩dp
最新推荐文章于 2020-10-23 13:30:58 发布