HDU 3720

    没什么好说的,最近太水,各种犯2...
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iostream>
#include <sstream>

using namespace std;

const int inf = 1000000000;

struct Player {
    string name;
    int ability;
    string position;
    
    bool operator < (const Player &oth) const {
        return position < oth.position;
    }
} player[23];

int additional[23][23];

int find(const string &name) {
    for (int i = 0; ; i++)
        if (player[i].name == name) return i;
}

int pd, pg, pm, ps;     // 分别是第一个后卫、第一个守门员、第一个中场、第一个前锋在player中的位置。
vector<int> select;
int ans;

void dfs(int x) {
    if (select.size() >= 11) {
        int tmp = 0;
        for (int i = 0; i < 11; i++) {
            tmp += player[select[i]].ability;
            for (int j = i + 1; j < 11; j++)
                tmp += additional[select[i]][select[j]];
        }
        if (tmp > ans) ans = tmp;
        return;
    }
    if (x >= 23) return;
    int y = x + 1;
    if (select.size() >= 9) {
        if (23 - y >= 11 - select.size()) dfs(y);   // 如果可以不选x
        select.push_back(x);
        if (select.size() == 11) y = 23;            // 如果选了x,已经有11人被选
        dfs(y);
        select.pop_back();
    } else if (select.size() >= 5) {
        if (ps - y >= 9 - select.size()) dfs(y);    // 如果可以不选x
        select.push_back(x);
        if (select.size() == 9) y = ps;             // 如果选了x,已经有9人被选(不需要中场了)
        dfs(y);
        select.pop_back();
    } else if (select.size() >= 4) {
        if (pm - y >= 5 - select.size()) dfs(y);    // 如果可以不选x
        select.push_back(x);
        if (select.size() == 5) y = pm;             // 如果选了x,已经有5人被选(不需要守门员了)
        dfs(y);
        select.pop_back();
    } else {
        if (pg - y >= 4 - select.size()) dfs(y);    // 如果可以不选x
        select.push_back(x);
        if (select.size() == 4) y = pg;             // 如果选了x,已经有4人被选(不需要后卫了)
        dfs(y);
        select.pop_back();
    }
}

int main() {
    int i, m, a, b, profit;
    string namea, nameb;
    while (cin >> player[0].name >> player[0].ability >> player[0].position) {
        for (i = 1; i < 23; i++)
            cin >> player[i].name >> player[i].ability >> player[i].position;
        sort(player, player + 23);
        cin >> m;
        memset(additional, 0, sizeof(additional));
        for (i = 0; i < m; i++) {
            cin >> namea >> nameb >> profit;
            a = find(namea);
            b = find(nameb);
            additional[a][b] =
            additional[b][a] = profit;
        }
        pd = pg = pm = ps = -1;
        for (i = 0; i < 23; i++) {
            switch (player[i].position[0]) {
            case 'd': if (pd == -1) pd = i; break;
            case 'g': if (pg == -1) pg = i; break;
            case 'm': if (pm == -1) pm = i; break;
            case 's': if (ps == -1) ps = i; break;
            }
        }
        if (pd == -1 || pg == -1 || pm == -1 || ps == -1 ||
            pg - pd < 4 || pm - pg < 1 || ps - pm < 4 || 23 - ps < 2) {
            cout << "impossible" << endl;
            continue;
        }
        ans = -inf;
        dfs(0);
        cout << ans << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值