编程介的小学生 2019-06-21 15:59 采纳率: 20.5%
浏览 181

足球队选球员如何选择11个人来使总价值最大化,怎么使用C语言的程序的设计的办法来解决的

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题