0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:11:58 +00:00

#2360. 「NOIP2016」换教室

https://loj.ac/s/1642945
This commit is contained in:
Baoshuo Ren 2022-11-24 12:11:13 +08:00
parent 1ef8dcd945
commit 61a6f5bd8c
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
51 changed files with 242 additions and 0 deletions

92
LibreOJ/2360/2360.cpp Normal file
View File

@ -0,0 +1,92 @@
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2005,
V = 305;
int n, m, v, e, c[N], d[N], g[V][V];
double p[N], f[N][N][2], ans = 1e9;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> v >> e;
memset(g, 0x3f, sizeof(g));
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
for (int i = 1; i <= n; i++) {
cin >> d[i];
}
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
for (int i = 1; i <= v; i++) {
g[i][i] = 0;
}
for (int i = 1, a, b, w; i <= e; i++) {
cin >> a >> b >> w;
g[a][b] = g[b][a] = std::min(g[a][b], w);
}
for (int k = 1; k <= v; k++) {
for (int i = 1; i <= v; i++) {
for (int j = 1; j <= v; j++) {
g[i][j] = std::min(g[i][j], g[i][k] + g[k][j]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= m; j++) {
f[i][j][0] = f[i][j][1] = 1e9;
}
}
f[1][0][0] = f[1][1][1] = 0;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= std::min(m, i); j++) {
f[i][j][0] = std::min(
f[i - 1][j][0]
+ g[c[i - 1]][c[i]],
f[i - 1][j][1]
+ p[i - 1] * g[d[i - 1]][c[i]]
+ (1.0 - p[i - 1]) * g[c[i - 1]][c[i]]);
if (j) {
f[i][j][1] = std::min(
f[i - 1][j - 1][0]
+ p[i] * g[c[i - 1]][d[i]]
+ (1.0 - p[i]) * g[c[i - 1]][c[i]],
f[i - 1][j - 1][1]
+ p[i - 1] * p[i] * g[d[i - 1]][d[i]]
+ (1.0 - p[i - 1]) * p[i] * g[c[i - 1]][d[i]]
+ p[i - 1] * (1.0 - p[i]) * g[d[i - 1]][c[i]]
+ (1.0 - p[i - 1]) * (1.0 - p[i]) * g[c[i - 1]][c[i]]);
}
}
}
for (int i = 0; i <= m; i++) {
ans = std::min({ans, f[n][i][0], f[n][i][1]});
}
cout << std::fixed << std::setprecision(2) << ans << endl;
return 0;
}

BIN
LibreOJ/2360/data/classroom1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom20.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom21.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom21.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom22.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom22.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom23.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom23.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom24.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom24.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom25.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom25.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2360/data/classroom9.in (Stored with Git LFS) Normal file

Binary file not shown.