hdu3720 Arranging Your Team

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

2010 Asia Tianjin Regional Contest

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;
}

  

时间: 2024-11-05 18:44:07

hdu3720 Arranging Your Team的相关文章

UVa 1627 - Team them up!——[0-1背包]

Your task is to divide a number of persons into two teams, in such a way, that: everyone belongs to one of the teams; every team has at least one member; every person in the team knows every other person in his team; teams are as close in their sizes

HDU 3296 &amp; POJ 3138 Acm Team Section(数学)

题目链接: HDU: http://acm.hdu.edu.cn/showproblem.php?pid=3296 POJ:  http://poj.org/problem?id=3138 Acm Team Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 159    Accepted Submission(s): 47

Team Queue

Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 129 Accepted Submission(s): 63   Problem Description Queues and Priority Queues are data structures which are known to most computer scie

team viewer - rollback framework could not be initialized

rollback framework could not be initialized, 在安装team viewer 的时候出现的这个错误信息,求大师帮忙 https://zhidao.baidu.com/question/521794345.html

Sample Apps by Android Team -- Amazed

Sample Apps by Android Team 代码下载:http://pan.baidu.com/s/1eSNmdUE 本次是项目Amazed代码学习记录. 一.创建自定义View @.在onSizeChanged中,通过如参w(宽)和h(高)的比较来判断手机是处于横向(Landscape)还是纵向(Portrait). @.在onDraw中进行自定义View的界面绘制. @.绘制界面需要Canvas和Paint: 1.Cnavas:用来控制画什么,比如画直线(drawLine).画矩

Uva 540.Team Queue

队列问题,思路较为清晰 通过模拟操作可以发现可以先队内排列,然后进行队伍排列 其中个别操作由于vector.map嵌套,可能会发生打错凌乱的情况. 1 #include <cstdio> 2 #include <vector> 3 #include <queue> 4 #include <map> 5 #include <algorithm> 6 7 using namespace std; 8 9 int kase=0; 10 11 class

team talk 主要框架

Android TeamTalk的原型是Android-IM, 注:本文假设你已经有Android开发环境,且对Android开发的基本常识有所了解 本文以eclipse为例启动Eclipse,导入Android客户端项目,请确保你当前的Android SDK是最新版. 如果编译出错,请修改项目根目录下的 project.properties 文件. 一.程序所依赖项目信息 1.mgimlibs git地址:http://gitlab.mogujie.org/androidop-team/mgi

Gun N&#39; Rose Team Review

一看到这个项目就被他的功能给吸引了.回忆起以前看到一个东西很新奇想去网上查询它是什么,但是又不知道应该怎样去描述它,于是在搜索引擎的输入框中键入.删除.键入.删除的可笑经历的时候,我就越发感觉到这个app的必要性了.画出查询对象的大致轮廓,系统自动搜筛选出相似的图片,这个app实现了“所见即所得”,令人称赞. 当然,这个app也存在很多局限性,比如说它返回的图片数量很大,没能实现精确定位,如果能让用户在输入时添加对对象的模糊描述,比如说:不是房子,像苹果等无疑将提高搜索的准确度.另外,这个app

@Team协作:新媒体初创公司的业绩屡创新高的秘密

共同协作这个词汇相信很多创业者都曾不止一次见过或者听说过,这个词汇的热门来自当下面对提高效率以及团队协同性拓展的需求,而作为从个人站长转型至创业者,当面对团队以及客户的时候,初创公司的效率决定了这家公司的寿命. 作 为一家新媒体初创公司,从一开始就选择了创业工具组合来完成产品的设计到团队的管理,再到业务的销售与客户关系维护,从产品原型设计Axure到邮件客户 端Foxmail,从金数据到IMO云办公室,我们的目的就是为了提高效率让团队更专注产品服务,但是零散的工具并没有起到太多的作用. 目前微信