题意简述: 有
n
个玩具,
数据范围:
题解: 一开始想暴搜,结果看周围人都纷纷网络流,我思索了一下,脑补了一个看起来很对的费用流,对于每个店建一个流量为
1
费用为一个很大的数的边,然后再建一条流量
正解居然真的是暴搜,姿势不同得分也很不同,因为
#include<bits/stdc++.h>
typedef long long ll;
const int N = 105;
struct rec{
int v, _x, _v, next;
} mp[N * 2];
int n, m, k, first[N], s;
ll f[N], ans;
void ins(int x, int v, int _x, int _v) {
mp[++s] = (rec) {v, _x, _v, first[x]};
first[x] = s;
}
void dfs(int dep, int pick, ll S, ll now) {
if (now - f[dep] > ans) return;
if (dep == m) {if (now < ans) ans = now; return;}
bool can_not_choose = 1;
for (int t = first[dep]; t; t = mp[t].next)
if (mp[t]._x <= dep && !(S & (1ll << mp[t]._x))) {can_not_choose = 0; break;}
if (can_not_choose) dfs(dep + 1, pick, S, now);
if (pick == k) return;
for (int t = first[dep]; t; t = mp[t].next) {
if (mp[t]._x >= dep || !(S & (1ll << mp[t]._x)))
now += mp[t].v;
else
if (mp[t].v < mp[t]._v)
now -= mp[t]._v - mp[t].v;
else;
}
dfs(dep + 1, pick + 1, S ^ (1ll << dep), now);
}
int main() {
freopen("toy.in", "r", stdin);
freopen("toy.out", "w", stdout);
scanf("%d%d%d", &n, &m, &k);
int a, p, b, q;
for (int i = 1; i <= n; i++) {
scanf("%d%d%d%d", &a, &p, &b, &q); a--, b--;
if (a == b) p = q = std::min(p, q);
ins(a, p, b, q); if (a != b) ins(b, q, a, p);
if (a > b) std::swap(a, b), std::swap(p, q);
if (q < p) for (int i = a; i <= b; i++) f[i] += p - q;
}
ans = 1e15;
dfs(0, 0, 0, 0);
if (ans == (ll)1e15)
printf("-1\n");
else
printf("%lld\n", ans);
return 0;
}