mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:08:47 +00:00
parent
2ec62c8df4
commit
939dc609f8
90
LibreOJ/6009/6009.cpp
Normal file
90
LibreOJ/6009/6009.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
const int N = 25,
|
||||||
|
M = 105;
|
||||||
|
const int INF = 0x3f3f3f3f;
|
||||||
|
|
||||||
|
int n, m;
|
||||||
|
std::array<int, M> a, b1, b2, f1, f2;
|
||||||
|
std::array<int, 1 << N> dist;
|
||||||
|
std::array<bool, 1 << N> vis;
|
||||||
|
|
||||||
|
bool check(int s, int i) {
|
||||||
|
if ((b1[i] | s) != s) return false;
|
||||||
|
if (b2[i] & s) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spfa(int s) {
|
||||||
|
std::fill(dist.begin(), dist.end(), INF);
|
||||||
|
|
||||||
|
std::queue<int> q;
|
||||||
|
q.push(s);
|
||||||
|
dist[s] = 0;
|
||||||
|
vis[s] = true;
|
||||||
|
|
||||||
|
while (!q.empty()) {
|
||||||
|
int u = q.front();
|
||||||
|
q.pop();
|
||||||
|
|
||||||
|
for (int i = 1; i <= m; i++) {
|
||||||
|
if (!check(u, i)) continue;
|
||||||
|
|
||||||
|
int v = u ^ (u & f1[i]) | f2[i];
|
||||||
|
|
||||||
|
if (dist[u] + a[i] < dist[v]) {
|
||||||
|
dist[v] = dist[u] + a[i];
|
||||||
|
|
||||||
|
if (!vis[v]) {
|
||||||
|
q.push(v);
|
||||||
|
vis[v] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vis[u] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> m;
|
||||||
|
|
||||||
|
for (int i = 1; i <= m; i++) {
|
||||||
|
std::string b, f;
|
||||||
|
|
||||||
|
cin >> a[i] >> b >> f;
|
||||||
|
|
||||||
|
for (int j = 0; j < b.size(); j++) {
|
||||||
|
if (b[j] == '+') {
|
||||||
|
b1[i] = b1[i] | 1 << j;
|
||||||
|
} else if (b[j] == '-') {
|
||||||
|
b2[i] = b2[i] | 1 << j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < f.size(); j++) {
|
||||||
|
if (f[j] == '-') {
|
||||||
|
f1[i] = f1[i] | 1 << j;
|
||||||
|
} else if (f[j] == '+') {
|
||||||
|
f2[i] = f2[i] | 1 << j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
spfa((1 << n) - 1);
|
||||||
|
|
||||||
|
cout << (dist[0] == INF ? 0 : dist[0]) << endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
LibreOJ/6009/data/bug1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug1.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug10.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug2.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug3.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug4.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug5.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug6.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug6.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug7.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug7.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug8.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug8.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug9.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/6009/data/bug9.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/6009/data/bug9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user