不可能解可以直接判断。

搭配产生的附加分可以用一个二维数组保存。

枚举1442,4种类型的人,因为总人数只有23个,所以可以搜索暴力枚举,然后保存最优解。

注意trick,答案可能为负数,所以初始化ans不能为0.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define maxn 1005
#define MAXN 100005
#define mod 1000000007
#define INF 0x3f3f3f3f
using namespace std; typedef long long ll;
char name[100];
char type[100];
int power[30];
int maps[30][30];
map<string,int> mt;
map<string,int> na;
int mp[30];
vector<int> player[4];
vector<int> ans;
int ANS;
void dfs2(int pos,int sum);
void dfs3(int pos,int sum);
void dfs4(int pos,int sum); void dfs1(int pos,int sum)
{
if(sum==1) {dfs2(-1,0);return;}
for(int i=pos+1;i<player[0].size();i++)
{
ans.push_back(player[0][i]);
dfs1(i,sum+1);
ans.pop_back();
}
}
void dfs2(int pos,int sum)
{
if(sum==4) {dfs3(-1,0);return;}
for(int i=pos+1;i<player[1].size();i++)
{
ans.push_back(player[1][i]);
dfs2(i,sum+1);
ans.pop_back();
}
}
void dfs3(int pos,int sum)
{
if(sum==4) {dfs4(-1,0);return;}
for(int i=pos+1;i<player[2].size();i++)
{
ans.push_back(player[2][i]);
dfs3(i,sum+1);
ans.pop_back();
}
}
void dfs4(int pos,int sum)
{
if(sum==2)
{
int s=0;
for(int i=0;i<ans.size();i++)
{
for(int j=i+1;j<ans.size();j++)
{
s+=maps[ans[i]][ans[j]];
}
s+=power[ans[i]];
}
ANS=max(s,ANS);
return;
}
for(int i=pos+1;i<player[3].size();i++)
{
ans.push_back(player[3][i]);
dfs4(i,sum+1);
ans.pop_back();
}
}
int main()
{
mt["goalkeeper"]=0;
mt["defender"]=1;
mt["midfielder"]=2;
mt["striker"]=3;
int p;
while(cin>>name)
{
ANS=-0x3f3f3f3f;
ans.clear();
na.clear();
for(int i=0;i<4;i++) player[i].clear(); cin>>p>>type;
player[mt[type]].push_back(1);
power[1]=p; na[name]=1;
for(int i=2;i<=23;i++)
{
cin>>name>>p>>type;
na[name]=i;
player[mt[type]].push_back(i);
power[i]=p;
}
int n;
memset(maps,0,sizeof(maps));
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>name>>type>>p;
maps[na[name]][na[type]]=p;
maps[na[type]][na[name]]=p;
} if(player[0].size()<1||player[1].size()<4||player[2].size()<4||player[3].size()<2)
{
cout<<"impossible"<<endl;
continue;
}
dfs1(-1,0);
cout<<ANS<<endl;
}
return 0;
}

hdu 3720 Arranging Your Team 枚举的更多相关文章

  1. HDU 3720 Arranging Your Team

    先分组,然后暴力:注意  初始化时不要为0 会有负数:我直接二进制枚举: dfs是正解:呵呵 #include <iostream> #include <cstdio> #in ...

  2. HDU 3720 Arranging Your Team(DFS)

    题目链接 队内赛里,匆匆忙忙写的. #include <cstdio> #include <cstring> #include <iostream> #includ ...

  3. hdu3720 Arranging Your Team

    Arranging Your Team Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. Arranging Your Team HDU - 3720 【DFS】

    思路 题意:此题大意是指首先给你23个队员的信息,包括他们的名字,能力值,在赛场上的职位.然后给出几个若能满足某两个队员同时在球场上就额外加上一定的值.最后让你从23个队员中选出11个人,使得最终的v ...

  5. HDU 3720 深搜 枚举

    DES:从23个队员中选出4—4—2—1共4种11人来组成比赛队伍.给出每个人对每个职位的能力值.给出m组人在一起时会产生的附加效果.问你整场比赛人员的能力和最高是多少. 用深搜暴力枚举每种类型的人选 ...

  6. HDU 5752 Sqrt Bo【枚举,大水题】

    Sqrt Bo Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  7. HDU 4763 Theme Section(KMP+枚举公共前后缀)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目大意: 给你一个字符串s,存在一个子串E同时出现在前缀.中间.后缀,即EAEBE这种模式,A ...

  8. hdu - 5128 The E-pang Palace(枚举+计算几何)

    http://acm.hdu.edu.cn/showproblem.php?pid=5128 给出n个点,求n个点组成两个矩形的最大面积. 矩形必须平行x轴,并且不能相交,但是小矩形在大矩形内部是可以 ...

  9. HDU 5303 Delicious Apples (贪心 枚举 好题)

    Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

随机推荐

  1. 【python】dir(__builtins__)查看python中所用BIF(内置函数)

    dir(__builtins__)查看python中所用BIF(内置函数)

  2. python调用java

    这么个标题多少有点蛋疼的感觉,两个都是互联网时代的语言,学习成本和执行效率也差不多,之所以会产生这种需求,多半是想在python中引用java的类,例如安卓和hadoop的生态圈,基本是java代码的 ...

  3. MySQL驱动阅读------Connection连接的建立,基于JDBC-----5.1.26

    一般获取数据库连接的程序 Class.forName("com.mysql.jdbc.Driver"); final Connection connection = (Connec ...

  4. Linq 数据合并,比较,连接,交叉 维恩图工具

    Except 返回包含两个不同之处的linq结果集 Intersect 返回两个容器中共同的数据项 Union 返回所有成员,相同的成员出现多次,将只返回一个 Concat 返回所有数据项

  5. Android AlertDialog更改标题颜色,字体等

    更改AlertDialog标题的方法google目前没有提供,只能通过其他办法 一种办法是:首先在源代码中找到有个叫AlertController的类,这个类就是AlertDialog的实现类,是没有 ...

  6. 14.6.3.5 Configuring InnoDB Buffer Pool Flushing

    14.6.3.5 Configuring InnoDB Buffer Pool Flushing InnoDB 执行某些任务在后台, 包括脏叶的刷新(那些已经发生改变的pages 但是没有写入到数据文 ...

  7. 【POJ】2503 Babelfish

    字典树简单题. #include <cstdio> #include <cstring> #include <cstdlib> typedef struct Tri ...

  8. Linux下把U盘格式化为fat32

    在linux下也是支持fat32的,如果U盘中了病毒可以插入linux系统进行格式化比较安全,下面介绍如何在linux下把u盘格式化为fat32的方法 一.执行fdisk -l查看linux设备,我的 ...

  9. 数学(概率)CodeForces 626D:Jerry's Protest

    Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds ...

  10. TMS320VC5509A DSP学习路线(持续更新)

    step 1:芯片的数据手册(data sheet) 参考资料:sprs205k_TMS320VC5509A Fixed-Point Digital Signal Processor Data Man ...