记录编号 544950 评测结果 AAAAAAAAAA
题目名称 [SYOI 2015] Asm.Def的枪榴弹 最终得分 100
用户昵称 Gravatarziiidan 是否通过 通过
代码语言 C++ 运行时间 0.020 s
提交时间 2019-10-23 22:14:39 内存使用 14.41 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>

using namespace std;

const int maxn = 17;
const int maxm = (1 << (maxn - 1));

int n;

int rob[maxn], fb[maxn], jia[maxn], yi[maxn], diao[maxn];

int f[maxm][3];

int read(void)
{
    int s = 0, w = 1;
    char ch = getchar();
    for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') w = -1;
    for(; ch <= '9' && ch >= '0'; ch = getchar()) s = s * 10 + ch - '0';
    return s * w;
}

inline bool check(int x, int y)
{
    int nd = 0;
    if(f[x][0] < rob[y]) nd += rob[y] - f[x][0];
    if(f[x][1] < fb[y]) nd += fb[y] - f[x][1];
    if(nd > f[x][2]) return false;
    return true;
}

int main()
{
    freopen("asm_grenade.in", "r", stdin);
    freopen("asm_grenade.out", "w", stdout);
    n = read();
    for(int i = 1; i <= n; i++) rob[i] = read();
    for(int i = 1; i <= n; i++) fb[i] = read();
    for(int i = 1; i <= n; i++) jia[i] = read();
    for(int i = 1; i <= n; i++) yi[i] = read();
    for(int i = 1; i <= n; i++) diao[i] = read();
    f[0][0] = read(); f[0][1] = read(); f[0][2] = read();
    int limit = (1 << n);
    limit--;
    for(int i = 0; i <= limit; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(i & (1 << (j - 1))) continue;
            if(check(i, j) == false) continue;
            int S = i | (1 << (j - 1));
            f[S][0] = f[i][0] - rob[j];
            f[S][1] = f[i][1] - fb[j];
            f[S][2] = f[i][2];
            if(f[S][0] < 0)
            {
                f[S][2] += f[S][0];
                f[S][0] = 0;
            }
            if(f[S][1] < 0)
            {
                f[S][2] += f[S][1];
                f[S][1] = 0;
            }
            f[S][0] += jia[j];
            f[S][1] += yi[j];
            f[S][2] += diao[j];
        }
    }
    int ans = -0x7fffffff;
    for(int i = 0; i <= limit; i++) ans = max(ans, f[i][0] + f[i][1] + f[i][2]);
    cout << ans << '\n';
    return 0;
}