mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-02-17 14:26:47 +00:00
Compare commits
6 Commits
32016ef417
...
0ea606148e
Author | SHA1 | Date | |
---|---|---|---|
0ea606148e | |||
9a5892035d | |||
79c0f8c1cb | |||
b2b98018a0 | |||
85478fb9d9 | |||
0e284dd5e1 |
84
Luogu/P5052/P5052.cpp
Normal file
84
Luogu/P5052/P5052.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 2005,
|
||||
M = 105;
|
||||
|
||||
int n, k, m, a[M], b[M], t[M], max, ans;
|
||||
// 访问过最左端的房子为 l
|
||||
// 最右端的房子为 r
|
||||
// 时间已经过了 k 秒
|
||||
// 目前正在 左(0) / 右(1) 端
|
||||
int f[M][M][N][2];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
memset(f, 0xc0, sizeof(f));
|
||||
|
||||
cin >> n >> k >> m;
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> a[i] >> b[i] >> t[i];
|
||||
|
||||
max = std::max(max, t[i]);
|
||||
}
|
||||
|
||||
int x = std::distance(a, std::lower_bound(a + 1, a + 1 + m, k)),
|
||||
y = std::distance(a, std::upper_bound(a + 1, a + 1 + m, k)) - 1;
|
||||
|
||||
if (a[x] == k) {
|
||||
f[x][x][0][0]
|
||||
= f[x][x][0][1]
|
||||
= (std::abs(a[x] - k) < t[x]) * b[x];
|
||||
} else { // 起始点没有宝可梦
|
||||
f[x][x][std::abs(a[x] - k)][0]
|
||||
= f[x][x][std::abs(a[x] - k)][1]
|
||||
= (std::abs(a[x] - k) < t[x]) * b[x];
|
||||
f[y][y][std::abs(a[y] - k)][0]
|
||||
= f[y][y][std::abs(a[y] - k)][1]
|
||||
= (std::abs(a[y] - k) < t[y]) * b[y];
|
||||
}
|
||||
|
||||
for (int len = 2; len <= m; len++) {
|
||||
for (int l = 1, r = l + len - 1; r <= m; l++, r++) {
|
||||
for (int k = a[r] - a[l]; k <= max; k++) {
|
||||
f[l][r][k][0] = std::max({
|
||||
f[l][r][k][0],
|
||||
f[l + 1][r][k - (a[l + 1] - a[l])][0] + (k < t[l]) * b[l],
|
||||
f[l + 1][r][k - (a[r] - a[l])][1] + (k < t[l]) * b[l],
|
||||
});
|
||||
|
||||
f[l][r][k][1] = std::max({
|
||||
f[l][r][k][1],
|
||||
f[l][r - 1][k - (a[r] - a[r - 1])][1] + (k < t[r]) * b[r],
|
||||
f[l][r - 1][k - (a[r] - a[l])][0] + (k < t[r]) * b[r],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int l = 1; l <= m; l++) {
|
||||
for (int r = l; r <= m; r++) {
|
||||
for (int k = 0; k <= max; k++) {
|
||||
ans = std::max({
|
||||
ans,
|
||||
f[l][r][k][0],
|
||||
f[l][r][k][1],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
149
S2OJ/1139/1139.cpp
Normal file
149
S2OJ/1139/1139.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
int k, nxt[15][1005];
|
||||
long long sum[15][1005], f[2][1005][(1 << 14) + 5],
|
||||
ans = std::numeric_limits<long long>::min();
|
||||
std::string s;
|
||||
std::vector<std::string> a{""};
|
||||
int root, cnt;
|
||||
|
||||
struct node {
|
||||
int val;
|
||||
int child[26], fail;
|
||||
|
||||
node()
|
||||
: val(0), fail(0) {
|
||||
std::fill(std::begin(child), std::end(child), 0);
|
||||
}
|
||||
} tr[1005];
|
||||
|
||||
void insert(std::string s, const int& _val) {
|
||||
int cur = root;
|
||||
|
||||
for (char c : s) {
|
||||
if (!tr[cur].child[c - 'a']) {
|
||||
tr[cur].child[c - 'a'] = ++cnt;
|
||||
}
|
||||
|
||||
cur = tr[cur].child[c - 'a'];
|
||||
}
|
||||
|
||||
tr[cur].val += _val;
|
||||
}
|
||||
|
||||
void build() {
|
||||
std::queue<int> q;
|
||||
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if (tr[root].child[i]) {
|
||||
q.emplace(tr[root].child[i]);
|
||||
}
|
||||
}
|
||||
|
||||
while (!q.empty()) {
|
||||
int cur = q.front();
|
||||
q.pop();
|
||||
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if (tr[cur].child[i]) {
|
||||
tr[tr[cur].child[i]].fail = tr[tr[cur].fail].child[i];
|
||||
q.emplace(tr[cur].child[i]);
|
||||
tr[tr[cur].child[i]].val += tr[tr[tr[cur].child[i]].fail].val;
|
||||
} else {
|
||||
tr[cur].child[i] = tr[tr[cur].fail].child[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> k;
|
||||
|
||||
for (int i = 1; i <= k; i++) {
|
||||
std::string t;
|
||||
int c;
|
||||
|
||||
cin >> t >> c;
|
||||
|
||||
insert(t, c);
|
||||
}
|
||||
|
||||
cin >> s;
|
||||
|
||||
build();
|
||||
|
||||
for (char c : s) {
|
||||
if (c == '?') {
|
||||
a.emplace_back("");
|
||||
} else {
|
||||
a.back().push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
for (int j = 0; j <= cnt; j++) {
|
||||
int cur = j;
|
||||
|
||||
for (char c : a[i]) {
|
||||
cur = tr[cur].child[c - 'a'];
|
||||
sum[i][j] += tr[cur].val;
|
||||
}
|
||||
|
||||
nxt[i][j] = cur;
|
||||
}
|
||||
}
|
||||
|
||||
memset(f, 0xc0, sizeof(f));
|
||||
|
||||
f[0][0][0] = 0;
|
||||
|
||||
for (int i = 0, x = 0; i < a.size(); i++, x ^= 1) {
|
||||
memset(f[x ^ 1], 0xc0, sizeof(f[x ^ 1]));
|
||||
|
||||
for (int j = 0; j <= cnt; j++) {
|
||||
for (int s = 0; s < 1 << 14; s++) {
|
||||
if (f[x][j][s] < -0x3f3f3f3f3f3f3f3f) continue;
|
||||
|
||||
int p = nxt[i][j];
|
||||
|
||||
if (i + 1 < a.size()) {
|
||||
for (int k = 0; k < 14; k++) {
|
||||
if (s & (1 << k)) continue;
|
||||
|
||||
f[x ^ 1][tr[p].child[k]][s | (1 << k)] = std::max(
|
||||
f[x ^ 1][tr[p].child[k]][s | (1 << k)],
|
||||
f[x][j][s] + sum[i][j] + tr[tr[p].child[k]].val);
|
||||
}
|
||||
} else {
|
||||
f[x ^ 1][p][s] = std::max(f[x ^ 1][p][s], f[x][j][s] + sum[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i <= cnt; i++) {
|
||||
for (int s = 0; s < 1 << 14; s++) {
|
||||
ans = std::max(ans, f[a.size() & 1][i][s]);
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1139/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value11.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value11.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value12.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value12.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value13.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value13.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value14.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value14.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value15.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value15.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value16.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value16.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value17.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value17.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value18.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value18.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value19.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value19.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value20.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value20.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1139/data/value9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1139/data/value9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
157
S2OJ/1484/1484.cpp
Normal file
157
S2OJ/1484/1484.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <queue>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1505,
|
||||
M = 5005;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
const int mod = 1e9 + 7;
|
||||
|
||||
int n, m, dist[N], deg[N], cnt_in[N], cnt_out[N], ans[M];
|
||||
std::vector<std::tuple<int, int, int>> g[N];
|
||||
std::tuple<int, int, int, bool> edges[M];
|
||||
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, w;
|
||||
|
||||
std::tie(v, w, std::ignore) = e;
|
||||
|
||||
if (dist[v] > dist[u] + w) {
|
||||
dist[v] = dist[u] + w;
|
||||
|
||||
q.emplace(dist[v], v);
|
||||
}
|
||||
}
|
||||
|
||||
vis[u] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void topo(int s) {
|
||||
std::fill(std::begin(deg), std::end(deg), 0);
|
||||
std::fill(std::begin(cnt_in), std::end(cnt_in), 0);
|
||||
std::fill(std::begin(cnt_out), std::end(cnt_out), 0);
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
if (std::get<3>(edges[i])) {
|
||||
deg[std::get<1>(edges[i])]++;
|
||||
}
|
||||
}
|
||||
|
||||
std::queue<int> q;
|
||||
std::vector<int> v;
|
||||
|
||||
cnt_in[s] = 1;
|
||||
q.emplace(s);
|
||||
|
||||
while (!q.empty()) {
|
||||
int u = q.front();
|
||||
|
||||
v.emplace_back(u);
|
||||
q.pop();
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v, w, id;
|
||||
|
||||
std::tie(v, w, id) = e;
|
||||
|
||||
if (std::get<3>(edges[id])) {
|
||||
cnt_in[v] = (static_cast<long long>(cnt_in[v]) + cnt_in[u]) % mod;
|
||||
|
||||
if (--deg[v] == 0) {
|
||||
q.emplace(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::for_each(v.rbegin(), v.rend(), [&](int u) {
|
||||
for (auto e : g[u]) {
|
||||
int v, w, id;
|
||||
|
||||
std::tie(v, w, id) = e;
|
||||
|
||||
if (std::get<3>(edges[id])) {
|
||||
cnt_out[u] = (static_cast<long long>(cnt_out[u]) + cnt_out[v]) % mod;
|
||||
}
|
||||
}
|
||||
|
||||
cnt_out[u] = (cnt_out[u] + 1) % mod;
|
||||
});
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1, u, v, w; i <= m; i++) {
|
||||
cin >> u >> v >> w;
|
||||
|
||||
g[u].emplace_back(v, w, i);
|
||||
edges[i] = {u, v, w, false};
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
dijkstra(i);
|
||||
|
||||
std::for_each(
|
||||
std::begin(edges) + 1,
|
||||
std::begin(edges) + m + 1,
|
||||
[&](auto &e) {
|
||||
int u = std::get<0>(e),
|
||||
v = std::get<1>(e),
|
||||
w = std::get<2>(e);
|
||||
|
||||
std::get<3>(e) = dist[u] + w == dist[v];
|
||||
});
|
||||
|
||||
topo(i);
|
||||
|
||||
for (int j = 1; j <= m; j++) {
|
||||
int u, v;
|
||||
bool is_short;
|
||||
|
||||
std::tie(u, v, std::ignore, is_short) = edges[j];
|
||||
|
||||
if (is_short) {
|
||||
ans[j] = (static_cast<long long>(ans[j])
|
||||
+ static_cast<long long>(cnt_in[u]) * cnt_out[v] % mod)
|
||||
% mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::copy_n(std::begin(ans) + 1, m, std::ostream_iterator<int>(cout, "\n"));
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1484/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/data9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/data9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1484/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1484/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
157
S2OJ/1845/1845.cpp
Normal file
157
S2OJ/1845/1845.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <queue>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1505,
|
||||
M = 5005;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
const int mod = 1e9 + 7;
|
||||
|
||||
int n, m, dist[N], deg[N], cnt_in[N], cnt_out[N], ans[M];
|
||||
std::vector<std::tuple<int, int, int>> g[N];
|
||||
std::tuple<int, int, int, bool> edges[M];
|
||||
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, w;
|
||||
|
||||
std::tie(v, w, std::ignore) = e;
|
||||
|
||||
if (dist[v] > dist[u] + w) {
|
||||
dist[v] = dist[u] + w;
|
||||
|
||||
q.emplace(dist[v], v);
|
||||
}
|
||||
}
|
||||
|
||||
vis[u] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void topo(int s) {
|
||||
std::fill(std::begin(deg), std::end(deg), 0);
|
||||
std::fill(std::begin(cnt_in), std::end(cnt_in), 0);
|
||||
std::fill(std::begin(cnt_out), std::end(cnt_out), 0);
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
if (std::get<3>(edges[i])) {
|
||||
deg[std::get<1>(edges[i])]++;
|
||||
}
|
||||
}
|
||||
|
||||
std::queue<int> q;
|
||||
std::vector<int> v;
|
||||
|
||||
cnt_in[s] = 1;
|
||||
q.emplace(s);
|
||||
|
||||
while (!q.empty()) {
|
||||
int u = q.front();
|
||||
|
||||
v.emplace_back(u);
|
||||
q.pop();
|
||||
|
||||
for (auto e : g[u]) {
|
||||
int v, w, id;
|
||||
|
||||
std::tie(v, w, id) = e;
|
||||
|
||||
if (std::get<3>(edges[id])) {
|
||||
cnt_in[v] = (static_cast<long long>(cnt_in[v]) + cnt_in[u]) % mod;
|
||||
|
||||
if (--deg[v] == 0) {
|
||||
q.emplace(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::for_each(v.rbegin(), v.rend(), [&](int u) {
|
||||
for (auto e : g[u]) {
|
||||
int v, w, id;
|
||||
|
||||
std::tie(v, w, id) = e;
|
||||
|
||||
if (std::get<3>(edges[id])) {
|
||||
cnt_out[u] = (static_cast<long long>(cnt_out[u]) + cnt_out[v]) % mod;
|
||||
}
|
||||
}
|
||||
|
||||
cnt_out[u] = (cnt_out[u] + 1) % mod;
|
||||
});
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 1, u, v, w; i <= m; i++) {
|
||||
cin >> u >> v >> w;
|
||||
|
||||
g[u].emplace_back(v, w, i);
|
||||
edges[i] = {u, v, w, false};
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
dijkstra(i);
|
||||
|
||||
std::for_each(
|
||||
std::begin(edges) + 1,
|
||||
std::begin(edges) + m + 1,
|
||||
[&](auto &e) {
|
||||
int u = std::get<0>(e),
|
||||
v = std::get<1>(e),
|
||||
w = std::get<2>(e);
|
||||
|
||||
std::get<3>(e) = dist[u] + w == dist[v];
|
||||
});
|
||||
|
||||
topo(i);
|
||||
|
||||
for (int j = 1; j <= m; j++) {
|
||||
int u, v;
|
||||
bool is_short;
|
||||
|
||||
std::tie(u, v, std::ignore, is_short) = edges[j];
|
||||
|
||||
if (is_short) {
|
||||
ans[j] = (static_cast<long long>(ans[j])
|
||||
+ static_cast<long long>(cnt_in[u]) * cnt_out[v] % mod)
|
||||
% mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::copy_n(std::begin(ans) + 1, m, std::ostream_iterator<int>(cout, "\n"));
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1845/data/ex_najkraci1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/ex_najkraci1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/ex_najkraci1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/ex_najkraci1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/ex_najkraci2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/ex_najkraci2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/ex_najkraci2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/ex_najkraci2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/ex_najkraci3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/ex_najkraci3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/ex_najkraci3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/ex_najkraci3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/najkraci9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/najkraci9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1845/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1845/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
84
S2OJ/1847/1847.cpp
Normal file
84
S2OJ/1847/1847.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 2005,
|
||||
M = 105;
|
||||
|
||||
int n, k, m, a[M], b[M], t[M], max, ans;
|
||||
// 访问过最左端的房子为 l
|
||||
// 最右端的房子为 r
|
||||
// 时间已经过了 k 秒
|
||||
// 目前正在 左(0) / 右(1) 端
|
||||
int f[M][M][N][2];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
memset(f, 0xc0, sizeof(f));
|
||||
|
||||
cin >> n >> k >> m;
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
cin >> a[i] >> b[i] >> t[i];
|
||||
|
||||
max = std::max(max, t[i]);
|
||||
}
|
||||
|
||||
int x = std::distance(a, std::lower_bound(a + 1, a + 1 + m, k)),
|
||||
y = std::distance(a, std::upper_bound(a + 1, a + 1 + m, k)) - 1;
|
||||
|
||||
if (a[x] == k) {
|
||||
f[x][x][0][0]
|
||||
= f[x][x][0][1]
|
||||
= (std::abs(a[x] - k) < t[x]) * b[x];
|
||||
} else { // 起始点没有宝可梦
|
||||
f[x][x][std::abs(a[x] - k)][0]
|
||||
= f[x][x][std::abs(a[x] - k)][1]
|
||||
= (std::abs(a[x] - k) < t[x]) * b[x];
|
||||
f[y][y][std::abs(a[y] - k)][0]
|
||||
= f[y][y][std::abs(a[y] - k)][1]
|
||||
= (std::abs(a[y] - k) < t[y]) * b[y];
|
||||
}
|
||||
|
||||
for (int len = 2; len <= m; len++) {
|
||||
for (int l = 1, r = l + len - 1; r <= m; l++, r++) {
|
||||
for (int k = a[r] - a[l]; k <= max; k++) {
|
||||
f[l][r][k][0] = std::max({
|
||||
f[l][r][k][0],
|
||||
f[l + 1][r][k - (a[l + 1] - a[l])][0] + (k < t[l]) * b[l],
|
||||
f[l + 1][r][k - (a[r] - a[l])][1] + (k < t[l]) * b[l],
|
||||
});
|
||||
|
||||
f[l][r][k][1] = std::max({
|
||||
f[l][r][k][1],
|
||||
f[l][r - 1][k - (a[r] - a[r - 1])][1] + (k < t[r]) * b[r],
|
||||
f[l][r - 1][k - (a[r] - a[l])][0] + (k < t[r]) * b[r],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int l = 1; l <= m; l++) {
|
||||
for (int r = l; r <= m; r++) {
|
||||
for (int k = 0; k <= max; k++) {
|
||||
ans = std::max({
|
||||
ans,
|
||||
f[l][r][k][0],
|
||||
f[l][r][k][1],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1847/data/ex_go1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1847/data/ex_go1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1847/data/ex_go1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1847/data/ex_go1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1847/data/ex_go2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1847/data/ex_go2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1847/data/ex_go2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1847/data/ex_go2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1847/data/go1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1847/data/go1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1847/data/go1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1847/data/go1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user