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. 对话机器学习大神Yoshua Bengio(上)

    Yoshua Bengio教授(个人主页)是机器学习大神之一,尤其是在深度学习这个领域.他连同Geoff Hinton老先生以及 Yann LeCun(燕乐存)教授,缔造了2006年开始的深度学习复兴 ...

  2. ios 设计软件

    briefs V1.0.5 download @ here:http://soft.macx.cn/5442.htm 密码:www.macx.cn

  3. Sqli-labs less 57

    Less-57 从代码中看到对id进行了 " " 的处理,所以此处我们构造的payload要进行 "" 的处理,示例payload: http://127.0. ...

  4. Java 8怎么了:局部套用vs闭包

    [编者按]本文作者为专注于自然语言处理多年的 Pierre-Yves Saumont,Pierre-Yves 著有30多本主讲 Java 软件开发的书籍,自2008开始供职于 Alcatel-Luce ...

  5. POJ 3253 Fence Repair(优先队列,哈夫曼树,模拟)

    题目 //做哈夫曼树时,可以用优先队列(误?) //这道题教我们优先队列的一个用法:取前n个数(最大的或者最小的) //哈夫曼树 //64位 //超时->优先队列,,,, //这道题的优先队列用 ...

  6. DevExpress TreeList 那些事儿

    1:TreeList绑定数据源 当我们给予TreeList 的 parentFieldName 和 KeyFieldName 两个属性之后 会自动的生成树结构. 1 var sql = @" ...

  7. java系统属性

    java系统属性 1. java.runtime.name:java的运行环境名称. 2. sun.boot.library.path:jdk\jre中的bin的路径 3. java.vm.versi ...

  8. github研究

    一个程序猿一定会用git,但是我还没怎么用过,平时真是懒啊,学习之!...

  9. LINUX输入输出与文件——续

    1 目录操作 改变目录或文件的访问权限 #include <sys/stat.h> int chmod(const char *path, mode_t mode); //mode形如07 ...

  10. sql只修改第一二行数据

    update t_table set colname=*  where a=1 order by id desc limit 1,2