mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:28:47 +00:00
parent
f590290667
commit
9ef51c1399
116
S2OJ/1912/1912.cpp
Normal file
116
S2OJ/1912/1912.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 305,
|
||||
M = 3e4 + 5;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
|
||||
int n, m, k, x[M], y[M], z[M];
|
||||
double p[N][N], f[N][N];
|
||||
std::vector<std::pair<int, int>> g[N];
|
||||
int dist[N];
|
||||
bool vis[N];
|
||||
|
||||
void dijkstra(int s) {
|
||||
std::fill(std::begin(dist), std::end(dist), INF);
|
||||
std::fill(std::begin(vis), std::end(vis), false);
|
||||
|
||||
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<>> q;
|
||||
|
||||
q.emplace(0, s);
|
||||
dist[s] = 0;
|
||||
|
||||
while (!q.empty()) {
|
||||
int u = q.top().second;
|
||||
q.pop();
|
||||
|
||||
if (vis[u]) continue;
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v = e.first,
|
||||
w = e.second;
|
||||
|
||||
if (dist[v] > dist[u] + w) {
|
||||
dist[v] = dist[u] + w;
|
||||
|
||||
q.emplace(dist[v], v);
|
||||
}
|
||||
}
|
||||
|
||||
vis[u] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void dfs(int u) {
|
||||
if (g[u].empty()) {
|
||||
std::copy(std::begin(p[u]), std::end(p[u]), std::begin(f[u]));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v = e.first;
|
||||
|
||||
dfs(v);
|
||||
|
||||
for (int i = k; i; i--) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
f[u][i] = std::max(f[u][i], f[u][i - j] + f[v][j] / g[u].size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = k; i; i--) {
|
||||
for (int j = 1; j <= i; j++) {
|
||||
f[u][i] = std::max(f[u][i], p[u][j] + f[u][i - j] * (1.0 - p[u][j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m >> k;
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> x[i] >> y[i] >> z[i];
|
||||
|
||||
g[x[i]].emplace_back(y[i], z[i]);
|
||||
g[y[i]].emplace_back(x[i], z[i]);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 1; j <= k; j++) {
|
||||
cin >> p[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
dijkstra(1);
|
||||
std::fill(std::begin(g), std::end(g), std::vector<std::pair<int, int>>());
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
if (dist[x[i]] + z[i] == dist[y[i]]) {
|
||||
g[x[i]].emplace_back(y[i], 0);
|
||||
}
|
||||
|
||||
if (dist[y[i]] + z[i] == dist[x[i]]) {
|
||||
g[y[i]].emplace_back(x[i], 0);
|
||||
}
|
||||
}
|
||||
|
||||
dfs(1);
|
||||
|
||||
cout << std::fixed << std::setprecision(6) << f[1][k] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1912/data/arrest1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/arrest9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/arrest9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/ex_arrest1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/ex_arrest1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/ex_arrest1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/ex_arrest1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/ex_arrest2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/ex_arrest2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/ex_arrest2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/ex_arrest2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1912/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1912/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user