比赛 Asm.Def战记之圣地亚哥“杯2015 评测结果 AAAAAAAAAA
题目名称 Asm.Def的枪榴弹 最终得分 100
用户昵称 CoolBoy小逴 运行时间 0.005 s
代码语言 C++ 内存使用 13.66 MiB
提交时间 2019-10-23 18:29:33
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define Re register
using namespace std;

const int maxn = 20;

int n;
int k1, k2, k3, flag, sum, ans, qwq;
int a[maxn], b[maxn], c[maxn], d[maxn], e[maxn], f[maxn];
int vis[maxn], v[maxn];

int f_;
char ch_;
template <class T>
	inline T read (T &x_){
		x_ = 0, f_ = 1, ch_ = getchar();
		while (ch_ > '9' || ch_ < '0'){if (ch_ == '-') f_ = -1; ch_ = getchar();}
		while (ch_ >= '0' && ch_ <= '9') x_ = (x_ << 3) + (x_ << 1) + ch_ - 48, ch_ = getchar();
		return x_ *= f_;
	}
	
inline int Max (int x, int y){
	return (x > y) ? x : y;
}
	
int Is_ok(int i){
	if (k1 >= a[i] && k2 >= b[i]) return 1;
	if (k1 < a[i] && k2 >= b[i] && (k1 + k3 >= a[i])) return 2;
	if (k1 >= a[i] && k2 < b[i] && (k2 + k3 >= b[i])) return 3;
	if (k1 < a[i] && k2 < b[i] && (k1 + k2 + k3 >= (a[i]+b[i]))) return 4;
	return 0;
}

int check(int i, int x, int y, int z){
	if (x >= a[i] && y >= b[i]) return 1;
	if (x < a[i] && y >= b[i] && (x + z) >= a[i]) return 2;
	if (x >= a[i] && y < b[i] && (y + z) >= b[i]) return 3;
	if (x < a[i] && y < b[i] && (x + y + z) >= (a[i]+b[i])) return 4;
	return 0;
}

int judge(){
	qwq = 0;
	for (register int i = n;i >= 1; --i){
		if (v[i]) continue;
		if (vis[i]) continue;
		qwq += f[i];
	}
	return qwq;
}

void dfs (int pos, int tot, int x, int y, int z){
	if (ans < tot) ans = tot;
	if (tot + judge() <= ans) return; 
	for (register int i = n;i >= 1; --i){
		if (v[i]) continue;
		if (vis[i]) continue;
		int pd = check(i, x, y, z);
		if (!pd) continue;
		int sum = x + y + z - a[i] - b[i] + c[i] + d[i] + e[i];
		vis[i] = 1;
		if (pd == 1)
			dfs (i, sum, x-a[i]+c[i], y-b[i]+d[i], z+e[i]);
		if (pd == 2)
			dfs (i, sum, c[i], y-b[i]+d[i], (x+z)-a[i]+e[i]);
		if (pd == 3)
			dfs (i, sum, x-a[i]+c[i], d[i], (y+z)-b[i]+e[i]);
		if (pd == 4)
			dfs (i, sum, c[i], d[i], sum-b[i]-c[i]);
		vis[i] = 0;
	}
}

int main(){
	freopen ("asm_grenade.in", "r", stdin);
	freopen ("asm_grenade.out", "w", stdout);
	read(n);
	for (Re int i = 1;i <= n; ++i) read(a[i]);
	for (Re int i = 1;i <= n; ++i) read(b[i]);
	for (Re int i = 1;i <= n; ++i) read(c[i]);
	for (Re int i = 1;i <= n; ++i) read(d[i]);
	for (Re int i = 1;i <= n; ++i) read(e[i]);
	for (Re int i = 1;i <= n; ++i) {
		f[i] = (c[i]+d[i]+e[i]-a[i]-b[i]);
	}
	read(k1); read(k2); read(k3);
	for (Re int i = 1;i <= n; ++i){
		if ((!c[i]) && (!d[i]) && (!e[i])) v[i] = 1;
		if ((c[i] + d[i] + e[i]) < (a[i] + b[i])) v[i] = 1;
	}
	for (Re int i = n;i >= 1; --i){
		if (v[i] == 1) continue;
		flag = Is_ok(i);
		if (!flag) continue;
		memset(vis, 0, sizeof (vis));
		vis[i] = 1;
		sum = k1 + k2 + k3 - a[i] - b[i] + c[i] + d[i] + e[i];
		if (flag == 1)
			dfs (i, sum, k1-a[i]+c[i], k2+d[i]-b[i], k3+e[i]);
		if (flag == 2)
			dfs (i, sum, c[i], k2+d[i]-b[i], k1+k3+e[i]-a[i]);
		if (flag == 3)
			dfs (i, sum, k1+c[i]-a[i], d[i], k2+k3+e[i]-b[i]);
		if (flag == 4)
			dfs (i, sum, c[i], d[i], sum-c[i]-d[i]);
	}
	printf ("%d\n", ans);
	return 0;
}