http://acm.hdu.edu.cn/showproblem.php?pid=3720

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<map>
#include<string>
using namespace std;
#define INF 0x3f3f3f
map<string,int>f;
struct node
{
char s[],po[];
int v,k;
}p[];
int pa[],flag,w[][],maxz;
void dfs(int x,int a,int b,int c,int d,int sum)
{
int i,j;
if(x==&&a==&&b==&&c==&&d==)
{
for(i =; i <= ; i++)
for(j = i+ ; j <= ; j++)
sum+=w[pa[i]][pa[j]];
maxz = max(maxz,sum);
flag = ;
return ;
}
if(x>) return ;
pa[a+b+c+d+] = x;
if(p[x].k == )
{
if(d<)
dfs(x+,a,b,c,d+,sum+p[x].v);
}
else if(p[x].k==)
{
if(b<)
dfs(x+,a,b+,c,d,sum+p[x].v);
}
else if(p[x].k==)
{
if(c<)
dfs(x+,a,b,c+,d,sum+p[x].v);
}
else if(a<)
{
dfs(x+,a+,b,c,d,sum+p[x].v);
}
dfs(x+,a,b,c,d,sum);
}
int main()
{
int i,n,v;
char s1[],s2[];
while(cin>>p[].s>>p[].v>>p[].po)
{
f.clear();
f[p[].s] = ;
maxz=-INF;flag=;
memset(w,,sizeof(w));
for(i = ; i <= ;i++)
{
cin>>p[i].s>>p[i].v>>p[i].po;
}
for(i = ; i <= ; i++)
{
if(strcmp(p[i].po,"defender")==)
p[i].k = ;
else if(strcmp(p[i].po,"midfielder")==)
p[i].k = ;
else if(strcmp(p[i].po,"striker")==)
p[i].k = ;
else p[i].k = ;
f[p[i].s] = i;
}
cin>>n;
for(i = ; i <= n ; i++)
{
getchar();
cin>>s1>>s2>>v;
w[f[s1]][f[s2]] = v;
w[f[s2]][f[s1]] = v;
}
dfs(,,,,,);
if(!flag) puts("impossible");
else printf("%d\n",maxz);
}
return ;
}

hdu3270Arranging Your Team(dfs)的更多相关文章

  1. HDU 3720 Arranging Your Team(DFS)

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

  2. 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  3. 2017ACM暑期多校联合训练 - Team 9 1005 HDU 6165 FFF at Valentine (dfs)

    题目链接 Problem Description At Valentine's eve, Shylock and Lucar were enjoying their time as any other ...

  4. 2017ACM暑期多校联合训练 - Team 1 1003 HDU 6035 Colorful Tree (dfs)

    题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented ...

  5. Arranging Your Team HDU - 3720 【DFS】

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

  6. POJ1112 Team Them Up![二分图染色 补图 01背包]

    Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   S ...

  7. HDU1426 DFS

    Sudoku Killer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. 【POJ 1112】Team Them Up!(二分图染色+DP)

    Description Your task is to divide a number of persons into two teams, in such a way, that: everyone ...

  9. 17111 Football team

    时间限制:1000MS  内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题   语言: C++;C Description As every one known, a footbal ...

随机推荐

  1. 【bzoj1007】[HNOI2008]水平可见直线

    1007: [HNOI2008]水平可见直线 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 5932  Solved: 2254[Submit][Sta ...

  2. 来自平时工作中的css知识的积累---持续补充中

    ① 现代浏览器中,<img>元素默认情况下底部会有空白,那么这个空白到底是从哪里来的? 解惑: method-one:猛戳 来自知乎的解答 method-two: 延伸阅读 what is ...

  3. 拆分Sql列中内容的拆分

    拆分Sql列中内容的拆分. /*按照符号分割字符串*/ create function [dbo].[m_split](@c varchar(2000),@split varchar(2)) retu ...

  4. 理解 Memory barrier

    理解 Memory barrier(内存屏障) 发布于 2014 年 04 月 21 日2014 年 05 月 15 日 作者 name5566 参考文献列表:http://en.wikipedia. ...

  5. poj 2749

    Building roads Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6091   Accepted: 2046 De ...

  6. tomcat 跨域

    http://www.360doc.com/content/14/0920/14/7909375_411017244.shtml http://www.tuicool.com/articles/Znq ...

  7. SQL四舍五入及两种舍入

    round() 遵循四舍五入把原值转化为指定小数位数,如:round(1.45,0) = 1;round(1.55,0)=2floor()向下取整 如:floor(1.45)= 1,floor(1.5 ...

  8. sshpass

    示例: ./sshpass -p ‘123456’  ssh -o StrictHostKeyChecking=no    root@192.168.1.15 ./sshpass -p ‘123456 ...

  9. JSTL Tag学习笔记(二)之<fmt: />

    JSTL的formatting tags可以用来格式化和显示文本.日期.时间.数字.如果在JSP页面中要用到该库提供的tag的话,需要引入如下taglib: <%@ taglib prefix= ...

  10. Cloudinsight Agent install script

    #!/bin/bash # Cloudinsight Agent install script. set -e logfile="ci-agent-install.log" gis ...