#include <bits/stdc++.h> usingnamespacestd; #define pb push_back #define mp make_pair #define F first #define S second typedeflonglong LL; typedef pair<int, int> pii; constint M = 9000; vector<pii> a; class Over9000Rocks { public: intcountPossibilities(vector <int> lowerBound, vector <int> upperBound){ int n = lowerBound.size(); for (int i = 0; i < 1 << n; ++i) { int l = 0, r = 0; for (int j = 0; j < n; ++j) { if (i >> j & 1) { l += lowerBound[j]; r += upperBound[j]; } } l = max(l, M + 1); if (l <= r) a.pb(mp(l, r)); } sort(a.begin(), a.end()); int R = 0, ans = 0; for (int i = 0; i < a.size(); ++i) { if (a[i].F > R) ans += a[i].S - a[i].F + 1; elseif (a[i].S > R) ans += a[i].S - R; R = max(R, a[i].S); } return ans; } };
550
Description
目大意:给定一张图,有T个点,现在有 n 个人要从0号点分别走到 1 ~ n 号点,每个人都是沿着自己最短路径走(有多条最短路径则可任意选一条)。如果在到达终点之前,有个人单独行动,则认为这个人是处在危险中的(只有一个人经过某条边)。问n个人该怎么走使得处在危险中的人数最少。
#include <bits/stdc++.h> usingnamespacestd; #define pb push_back #define mp make_pair #define F first #define S second typedeflonglong LL; typedef pair<int, int> pii; constint N = 55; int d[N][N], f[N][N], l[N]; bool vis[N]; boolfind(int u, int n){ for (int i = 1; i <= n; ++i) { if (f[u][i] && !vis[i]) { vis[i] = 1; if (!l[i] || find(l[i], n)) { l[i] = u; return1; } } } return0; } class SafeReturn { public: intminRisk(int T, vector <string> streets){ int n = streets.size(); memset(d, 63, sizeof(d)); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (streets[i][j] != '-') d[i][j] = streets[i][j] - '0'; for (int i = 0; i < n; ++i) d[i][i] = 0; for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); for (int i = 1; i <= T; ++i) for (int j = 1; j <= T; ++j) if (i != j && d[0][j] + d[j][i] == d[0][i]) f[i][j] = 1; int ans = T; for (int i = 1; i <= T; ++i) { memset(vis, 0, sizeof(vis)); if (find(i, T)) --ans; } return ans; } };