比赛 Asm.Def战记之圣地亚哥“杯2015 评测结果 AAAAAAAAAA
题目名称 Asm.Def的枪榴弹 最终得分 100
用户昵称 氢氦 运行时间 3.849 s
代码语言 C++ 内存使用 13.66 MiB
提交时间 2019-10-23 17:56:18
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define max(a, b) ((a) > (b) ? (a) : (b))

const int ziiidan_NB = 3e6 + 8;
using std::next_permutation;
int n, now_c, now_d, now_e;

struct Node {
	int a, b, c, d, e;
}f[20];

namespace baoli {
	int ans, p[20];

	bool check(int a, int b, int c, int i) {
		if (a < f[i].a) {
			if (a + c < f[i].a) return false;
			a = 0, c -= (f[i].a - a);
		}
		if (b < f[i].b) 
			if (b + c < f[i].b) return false;
		return true;
	}

	void solve() {
		for (int i = 1; i <= n; i++) p[i] = i;
		ans = now_c + now_d + now_e; int tot = 0;
		do {
			++tot; if (tot == ziiidan_NB) break;
			int tmp1 = now_c, tmp2 = now_d, tmp3 = now_e;
			for (int i = 1; i <= n; i++) {
				if (!check(tmp1, tmp2, tmp3, p[i])) continue;
				if (tmp1 > f[p[i]].a) tmp1 -= f[p[i]].a;
				else tmp3 -= (f[p[i]].a - tmp1), tmp1 = 0;
				if (tmp2 > f[p[i]].b) tmp2 -= f[p[i]].b;
				else tmp3 -= (f[p[i]].b - tmp2), tmp2 = 0;
				tmp1 += f[p[i]].c, tmp2 += f[p[i]].d, tmp3 += f[p[i]].e;
				ans = max(ans , tmp1 + tmp2 + tmp3);
			}
		} while (next_permutation(p + 1 , p + n + 1));
		printf("%d\n", ans);
	}
}

int main() {
	freopen("asm_grenade.in", "r", stdin);
	freopen("asm_grenade.out", "w", stdout);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &f[i].a);
	for (int i = 1; i <= n; i++) scanf("%d", &f[i].b);
	for (int i = 1; i <= n; i++) scanf("%d", &f[i].c);
	for (int i = 1; i <= n; i++) scanf("%d", &f[i].d);
	for (int i = 1; i <= n; i++) scanf("%d", &f[i].e);
	scanf("%d%d%d", &now_c, &now_d, &now_e);
	baoli::solve();
	return 0;
}

/*
3
1 2 3
0 4 9
0 0 10
0 8 9
1 0 8
3 1 2
复杂度O(玄学)
*/