UVAL 5025 Arranging Your Team 暴力

题意:给出足球队中23个人每个人的位置和收益。同时,给出一个列表,表示如果这两个人同时上场,会有一个附加的收益。问:能否组成一个4-4-2-1的阵型,如果可以以,求出最大收益。

思路:因为只有23个队员,我们暴力搜索即可。姿势一定要好呀。

代码如下:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <map>

using namespace std;

const int INF = 0x3f3f3f3f;

char name[40],position[40];
char s1[40],s2[40];
vector<string> vec;
vector<int> ans;
vector<int> abit;
vector<int> pos;
int w[40][40];
int cnt[10];
int limit[10];
int ability;
int N,c,ret;

int trans()
{
    if(position[0] == 'd') return 0;
    if(position[0] == 'm') return 1;
    if(position[0] == 's') return 2;
    return 3;
}

void init()
{
    vec.clear();
    ans.clear();
    abit.clear();
    pos.clear();
    memset(w,0,sizeof(w));
    memset(cnt,0,sizeof(cnt));
}
void dfs(int p)
{
    if(ans.size() == 11){
        int tmp = 0;
        for(int i = 0; i < 11; ++i)
            tmp += abit[ans[i]];
        for(int i = 0; i < 11; ++i)
            for(int j = i + 1; j < 11; ++j)
                tmp += w[ans[i]][ans[j]];
        ret = max(ret, tmp);
        return;
    }
    if(p == 23) return;
    if(cnt[pos[p]] < limit[pos[p]]){
        cnt[pos[p]]++;
        ans.push_back(p);
        dfs(p+1);
        ans.pop_back();
        cnt[pos[p]]--;
    }
    dfs(p+1);
}

int main(void)
{
    //freopen("input.txt","r",stdin);
    limit[0] = 4;
    limit[1] = 4;
    limit[2] = 2;
    limit[3] = 1;
    while(scanf("%s %d %s",name,&ability,position) != EOF)
    {
        init();
        vec.push_back(name);
        abit.push_back(ability);
        pos.push_back(trans());
        for(int i = 0; i < 22; ++i){
            scanf("%s %d %s",name,&ability,position);
            vec.push_back(name);
            abit.push_back(ability);
            pos.push_back(trans());
        }
        scanf("%d", &N);
        for(int i = 0 ; i < N; ++i){
            scanf("%s %s %d",s1,s2,&c);
            int u = find(vec.begin(),vec.end(),string(s1)) - vec.begin();
            int v = find(vec.begin(),vec.end(),string(s2)) - vec.begin();
            w[u][v] = w[v][u] = c;
        }
        if(count(pos.begin(),pos.end(),0) < 4 ||
           count(pos.begin(),pos.end(),1) < 4 ||
           count(pos.begin(),pos.end(),2) < 2 ||
           count(pos.begin(),pos.end(),3) < 1)
        puts("impossible");
        else{
            ret = -INF;
            dfs(0);
            printf("%d\n",ret);
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值