Wannafly & Comet OJ 夏季欢乐赛(2019)G-篮球校赛

题目链接:传送门

标题有点长
不过没关系
很一眼的费用流
比赛的时候加边有点小错误
T T T W A WA WA R E RE RE
然后三天后的现在才找到啊哈哈哈
差点疯辽

源点 S S S 0 0 0
向每个人连边费用为 0 0 0流量为 1 1 1
每个人向五个任务连边费用为负的那个费用流量为 1 1 1
因为我们跑的是最大费用
五个任务向汇点 T T T连边费用为 0 0 0流量为 1 1 1
建模很显然
拆了点控制流量虽然没用但也没关系
当时建模建的很对!
加边的时候连了 5 ∗ n 5*n 5n条任务到 T T T硬是没看出来!
还有边的序号一开始一定是奇数一定是奇数一定是奇数
long long别小气
点只有 1 e 5 1e5 1e5
边会到 1 e 5 ∗ ( 2 + 5 ∗ 2 ) 1e5*(2+5*2) 1e5(2+52)也就是一百二十万

事实证明正解是贪心~
每种任务选出前五个孩
因为其他人不可能作为答案的一个
然后dfs这些孩选最优
我这是歪解

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define A 1200010
#define B 100010

using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
struct node {
	int next, to; ll w, f;
}e[A];
int head[B], num = 1;
void add(int fr, int to, ll w, ll f) {
	e[++num].next = head[fr]; e[num].to = to;
	e[num].w = w; e[num].f = f; head[fr] = num;
	swap(to, fr);
	e[++num].next = head[fr]; e[num].to = to;
	e[num].w = -w; e[num].f = 0; head[fr] = num;
}
int n, S, T, pre[B], last[B], vis[B];
ll dis[B], w, minn, flow[B];
queue<int> q;
bool SPFA() {
	memset(dis, 0x7f, sizeof dis);
	memset(flow, 0x7f, sizeof flow);
	memset(vis, 0, sizeof vis);
	q.push(S); vis[S] = 1; dis[S] = 0; pre[T] = -1;
	while (!q.empty()) {
		int fr = q.front(); q.pop(); vis[fr] = 0;
		for (int i = head[fr]; ~i; i = e[i].next) {
			int ca = e[i].to;
			if (e[i].f and dis[ca] > dis[fr] + e[i].w) {
				dis[ca] = dis[fr] + e[i].w;
				pre[ca] = fr; last[ca] = i;
				flow[ca] = min(flow[fr], e[i].f);
				if (!vis[ca]) {
					vis[ca] = 1;
					q.push(ca);
				}
			}
		}
	}
	return pre[T] != -1;
}
void EK() {
	while (SPFA()) {
		int fr = T;
		minn += flow[T] * dis[T];
		while (fr != S) {
			e[last[fr]].f -= flow[T];
			e[last[fr] ^ 1].f += flow[T];
			fr = pre[fr];
		}
	}
}

int main(int argc, char const *argv[]) {
	memset(head, -1, sizeof head);
	cin >> n; S = 0; T = n + 6;
	for (int i = 1; i <= 5; i++) add(n + i, T, 0, 1);
	for (int i = 1; i <= n; i++) {
		add(S, i, 0, 1);
		for (int j = 1; j <= 5; j++) {
			scanf("%lld", &w);
			add(i, n + j, -w, 1);
		}
	}
	EK(); cout << -minn << endl; return 0;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

良月澪二

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值