Arranging Your Team

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1218    Accepted Submission(s): 360

Problem Description
Your country has qualified for the FIFA 2010 South Africa World Cup. As the coach, you have made up the 23 men squad. Now you must select 11 of them as the starters. As is well known, there are four positions in soccer: goalkeeper, defender, midfielder and striker. Your favorite formation is 4-4-2, that is, you should choose 4 defenders, 4 midfielders, 2 strikers, and of course, 1 goalkeeper. As a retired ACMer, you want to write a program to help you make decision. Each person's ability has been evaluated as a positive integer. And what's more, for some special pairs of persons, if the two people are both on the field, there will be an additional effect (positive or negative). Now you should choose the 11 persons to make the total value maximum.
 
Input
There are multiple test cases, separated by an empty line. The first 23 lines of each test case indicate each person's name Si, ability value Vi, and position. The length of each name is no more than 30, and there are no whitespaces in the names. All the names are different. The ability values are positive integers and no more than 100. The position is one of "goalkeeper", "defender", "midfielder" and "striker".

Then an integer M indicates that there are M special pairs. Each of the following M lines contains Si, Sj and Cij, means that if Si and Sj are both on the field, the additional profit is Cij. (-100 ≤ Cij ≤ 100). Si and Sj are different strings, and must be in the previous 23 names. All the (Si, Sj) pairs
are different.

 
Output
Output one line for each test case, indicating the maximum total ability values, that is, the total ability values of the 11 persons plus the additional effects. If you cannot choose a 4-4-2 formation, output "impossible" instead.
 
Sample Input
Buffon 90 goalkeeper
De_Sanctis 80 goalkeeper
Marchetti 80 goalkeeper
Zambrotta 90 defender
Cannavaro 90 defender
Chiellini 90 defender
Maggio 90 defender
Bonucci 80 defender
Criscito 80 defender
Bocchetti 80 defender
Pirlo 90 midfielder
Gattuso 90 midfielder
De_Rossi 90 midfielder
Montolivo 90 midfielder
Camoranesi 80 midfielder
Palombo 80 midfielder
Marchisio 80 midfielder
Pepe 80 midfielder
Iaquinta 90 striker
Di_Natale 90 striker
Gilardino 80 striker
Quagliarella 80 striker
Pazzini 80 striker
1
Pirlo Quagliarella 50

ZhangSan01 50 goalkeeper
ZhangSan02 50 defender
ZhangSan03 50 defender
ZhangSan04 50 defender
ZhangSan05 50 defender
ZhangSan06 50 defender
ZhangSan07 50 defender
ZhangSan08 50 defender
ZhangSan09 50 defender
ZhangSan10 50 defender
ZhangSan11 50 defender
ZhangSan12 50 defender
ZhangSan13 50 defender
ZhangSan14 50 defender
ZhangSan15 50 defender
ZhangSan16 50 midfielder
ZhangSan17 50 midfielder
ZhangSan18 50 midfielder
ZhangSan19 50 midfielder
ZhangSan20 50 midfielder
ZhangSan21 50 midfielder
ZhangSan22 50 midfielder
ZhangSan23 50 midfielder
0

 
Sample Output
1030
impossible
 
Source
 
Recommend
zhouzeyong
 
题意:。。懒得打,身为体育迷一看就懂把。
思路:搜索。适当剪枝即可。
/*
* Author: Joshua
* Created Time: 2014年08月29日 星期五 18时52分48秒
* File Name: hdu3720.cpp
*/
#include<cstdio>
#include<cstring>
#include<map>
#include<string>
using namespace std;
#define inf 100000000
char s[35],ps[35];
map<string,int> mp;
const int limit[5]={0,1,4,4,2};
int v[25],g[25][25],id[25],cnt[5],t[12],ans; int gao(char x[])
{
if (x[0]=='g') return 1;
if (x[0]=='d') return 2;
if (x[0]=='m') return 3;
return 4;
} void init()
{
int m,x;
mp.clear();
memset(g,0,sizeof(g));
for (int i=1;i<=23;++i)
{
mp[s]=i;
id[i]=gao(ps);
if (i<23) scanf("%s%d%s",s,&v[i+1],ps);
}
scanf("%d",&m);
for (int i=1;i<=m;++i)
{
scanf("%s%s%d",s,ps,&x);
g[mp[s]][mp[ps]]=x;
g[mp[ps]][mp[s]]=x;
}
} void updata()
{
int temp=0;
for (int i=1;i<=11;++i)
temp+=v[t[i]];
for (int i=1;i<=11;++i)
for (int j=i+1;j<=11;++j)
temp+=g[t[i]][t[j]];
if (temp>ans) ans=temp;
} void dfs(int x,int y)
{
if (y==11)
{
updata();
return;
}
if (x>23) return;
for (int i=0;i<=1;++i)
{
cnt[id[x]]+=i;
if (cnt[id[x]]<=limit[id[x]])
{ if (i) t[y+1]=x;
dfs(x+1,y+i);
}
cnt[id[x]]-=i;
}
} void solve()
{
memset(cnt,0,sizeof(cnt));
ans=-inf;
dfs(1,0);
if (ans==-inf) printf("impossible\n");
else printf("%d\n",ans);
} int main()
{
while (scanf("%s%d%s",s,&v[1],ps)!=EOF)
{
init();
solve();
}
return 0;
}

  

hdu3720 Arranging Your Team的更多相关文章

  1. HDU 3720 Arranging Your Team(DFS)

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

  2. hdu 3720 Arranging Your Team 枚举

    不可能解可以直接判断. 搭配产生的附加分可以用一个二维数组保存. 枚举1442,4种类型的人,因为总人数只有23个,所以可以搜索暴力枚举,然后保存最优解. 注意trick,答案可能为负数,所以初始化a ...

  3. HDU 3720 Arranging Your Team

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

  4. Arranging Your Team

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=35800#problem/D #include <iostream> #inc ...

  5. Arranging Your Team HDU - 3720 【DFS】

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

  6. Configure a VLAN on top of a team with NetworkManager (nmcli) in RHEL7

    SOLUTION VERIFIED September 13 2016 KB1248793 Environment Red Hat Enterprise Linux 7 NetworkManager ...

  7. Create a Team in RHEL7

    SOLUTION VERIFIED September 13 2016 KB2620131 Environment Red Hat Enterprise Linux 7 NetworkManager ...

  8. Team Leader 你不再只是编码, 来炖一锅石头汤吧

    h3{ color: #000; padding: 5px; margin-bottom: 10px; font-weight: bolder; background-color: #ccc; } h ...

  9. Configure bridge on a team interface using NetworkManager in RHEL 7

    SOLUTION IN PROGRESS February 29 2016 KB2181361 environment Red Hat Enterprise Linux 7 Teaming,Bridg ...

随机推荐

  1. linux kill杀死进程

    背景:这个命令总是记不住,在此稍作记录,方便查看! 1 杀死进程 1.1 查看进程 此时如果我想杀了火狐的进程就在终端输入: $ kill -s 9 1827 其中-s 9 制定了传递给进程的信号是9 ...

  2. Spring mybatis源码篇章-SqlSessionFactoryBean

    前言:通过实例结合源码的方式解读,其中涉及到的文件来自于博主的Github毕设项目SchoolActivity_WxServer,引用的jar包为mybatis-spring-1.3.0.jar Sp ...

  3. Spring源码情操陶冶-AbstractApplicationContext#finishRefresh

    承接前文Spring源码情操陶冶-AbstractApplicationContext#finishBeanFactoryInitialization 约定web.xml配置的contextClass ...

  4. html5图片上传时IOS和Android均显示摄像头拍照和图片选择

    最近在做信开发时,发现<input type="file" />在IOS中可以拍照或从照片图库选择,而Android系统则显示资源管理器,无拍照选项,网上查找资料,改为 ...

  5. python几种常见语法

    NO1.type自动匹配类型 name="zhangsan"age=18 print (type(name))#type自动匹配类型 print ("name:%s,ag ...

  6. PAT (Basic Level) Practise (中文) 1017. A除以B (20)

    1017. A除以B (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求计算A/B,其中A是不超过 ...

  7. 编写一个简单的TCP服务端和客户端

    下面的实验环境是linux系统. 效果如下: 1.启动服务端程序,监听在6666端口上  2.启动客户端,与服务端建立TCP连接  3.建立完TCP连接,在客户端上向服务端发送消息 4.断开连接 实现 ...

  8. AngularJS优缺点、使用场景

    AngularJS 优缺点 优点: AngularJS模板功能强大丰富,自带了极其丰富的angular指令. AngularJS是完全可扩展的,与其他库的兼容效果很好,每一个功能可以修改或更换,以满足 ...

  9. 计蒜客模拟赛D2T1 蒜头君的兔子:矩阵快速幂

    题目链接:https://nanti.jisuanke.com/t/16442 题意: 有个人在第一年送了你一对1岁的兔子.这种兔子刚生下来的时候算0岁,当它在2~10岁的时候,每年都会生下一对兔子, ...

  10. Vue自定义事件

    前面的话 父组件使用props传递数据给子组件,子组件怎么跟父组件通信呢?这时,Vue的自定义事件就派上用场了.本文将详细介绍Vue自定义事件 事件绑定 每个 Vue 实例都实现了事件接口 (Even ...