# P1850 换教室

dp[i][j][1]为前j个数中申请了j个课，且当前申请的状态

dp[i][j][0] = min(dp[i - 1][j][0] + f[c[i - 1]][c[i]], dp[i - 1][j][1] + k[i - 1] * f[d[i - 1]][c[i]] + (1.00 - k[i - 1]) * f[c[i - 1]][c[i]]);
dp[i][j][1] = min(dp[i - 1][j - 1][0] + f[c[i - 1]][c[i]] * (1.00 - k[i]) + f[c[i - 1]][d[i]] * k[i], dp[i - 1][j - 1][1] + (f[c[i - 1]][c[i]] * (1.00 - k[i - 1]) * (1.00 - k[i])) + (f[c[i - 1]][d[i]] * (1.00 - k[i - 1]) * k[i]) + (f[d[i - 1]][c[i]] * k[i - 1] * (1.00 - k[i])) + (f[d[i - 1]][d[i]] * k[i - 1] * k[i]));

#include<bits/stdc++.h>
using namespace std;
const int N = 2005;
const int M = 305;
int c[N], d[N];
double k[N];
double dp[N][N][2];
double f[M][M];
int main()
{
int n, m, v, e;
scanf("%d %d %d %d", &n, &m, &v, &e);
for(int i = 1; i <= n; i++)
scanf("%d", &c[i]);
for(int i = 1; i <= n; i++)
scanf("%d", &d[i]);
for(int i = 1; i <= n; i++)
scanf("%lf", &k[i]);
for(int i = 1; i <= v; i++)
for(int j = 1; j <= v; j++)
f[i][j] = 1e9 + 7;
for(int i = 1; i <= v; i++)
f[i][i] = 0;
for(int i = 1; i <= n; i++)
for(int j = 0; j <= n; j++)
dp[i][j][0] = dp[i][j][1] = 1e9 + 7;
while(e--)
{
int a, b;
double w;
scanf("%d %d %lf", &a, &b, &w);
f[a][b] = f[b][a] = min(w,f[a][b]);
}
for(int k = 1; k <= v; k++)
for(int i = 1; i <= v; i++)
for(int j = 1;j <= v; j++)
f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
dp[1][0][0] = dp[1][1][1] = 0;
for(int i = 2; i <= n; i++)
{
dp[i][0][0] = dp[i - 1][0][0] + f[c[i - 1]][c[i]];
for(int j = 1; j <= m; j++)
{
dp[i][j][0] = min(dp[i - 1][j][0] + f[c[i - 1]][c[i]], dp[i - 1][j][1] + k[i - 1] * f[d[i - 1]][c[i]] + (1.00 - k[i - 1]) * f[c[i - 1]][c[i]]);
dp[i][j][1] = min(dp[i - 1][j - 1][0] + f[c[i - 1]][c[i]] * (1.00 - k[i]) + f[c[i - 1]][d[i]] * k[i], dp[i - 1][j - 1][1]
+ (f[c[i - 1]][c[i]] * (1.00 - k[i - 1]) * (1.00 - k[i]))
+ (f[c[i - 1]][d[i]] * (1.00 - k[i - 1]) * k[i])
+ (f[d[i - 1]][c[i]] * k[i - 1] * (1.00 - k[i]))
+ (f[d[i - 1]][d[i]] * k[i - 1] * k[i]));
}
}
double ans = 1e9 + 7;
for(int i = 0; i <= m; i++)
ans = min(ans, min(dp[n][i][0], dp[n][i][1]));
printf("%.2f\n", ans);
return 0;
}


10-25 104

09-11 266
09-17 15
10-07 40
06-13 343
08-20
12-18 41万+
02-15