hdu3270Arranging Your Team(dfs)
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)的更多相关文章
- HDU 3720 Arranging Your Team(DFS)
题目链接 队内赛里,匆匆忙忙写的. #include <cstdio> #include <cstring> #include <iostream> #includ ...
- 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 ...
- 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 ...
- 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 ...
- Arranging Your Team HDU - 3720 【DFS】
思路 题意:此题大意是指首先给你23个队员的信息,包括他们的名字,能力值,在赛场上的职位.然后给出几个若能满足某两个队员同时在球场上就额外加上一定的值.最后让你从23个队员中选出11个人,使得最终的v ...
- POJ1112 Team Them Up![二分图染色 补图 01背包]
Team Them Up! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7608 Accepted: 2041 S ...
- HDU1426 DFS
Sudoku Killer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 【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 ...
- 17111 Football team
时间限制:1000MS 内存限制:65535K 提交次数:0 通过次数:0 题型: 编程题 语言: C++;C Description As every one known, a footbal ...
随机推荐
- Linux查看日志命令
tail -f /var/log/apport.log more /var/log/xorg.0.log cat /var/log/mysql.err less /var/log/messages g ...
- 141029 V7 异步通知测试,15分钟循环代码重构,同步更新payInfo测试,支付成功timer测试成功说明
支付成功之后的1分钟定时任务:测试成功. 2014-10-29 17:16:06,892 DEBUG [http-bio-8086-exec-1] org.springframework.web.se ...
- Sqli-labs less 65
Less-65 $id = '"'.$id.'"'; // Querry DB to get the correct output $sql="SELECT * FROM ...
- HDU 3642 Get The Treasury (线段树扫描线,求体积并)
参考链接 : http://blog.csdn.net/zxy_snow/article/details/6870127 题意:给你n个立方体,求覆盖三次以上(包括三次)的区域的体积 思路:先将z坐标 ...
- Android activity属性
android:allowTaskReparenting 是否允许activity更换从属的任务,比如从短信息任务 切换到浏览器任务. android:alwaysRetainTaskState 是否 ...
- springmvc web应用程序 java
搭建普通 springmvc 1.如图建立相关文件 建立在WEB-INF下比较安全,不能直接访问资源. 2.建立Controller控制器,如图 3.需要导入的jar包 commons-logging ...
- 23种设计模式学习一(单列模式)singleton
单列模式的类(单线程下的) class Singleton { private static Singleton instance; private Singleton() { } public st ...
- YARN集群维护部分问题汇总
云梯开发人员在云梯Yarn集群的搭建和维护过程中做了许多工作,本文选择这期间部分较为典型的问题,通过对这些问题的分析和解决方案,为大家分享分布式系统问题调查的经验. 调查的问题 1. 2013年初引入 ...
- converntion
One convention that we have is to use the names of fruits and vegetables for variables(only in small ...
- hdu 1847 Good Luck in CET-4 Everybody!(简单博弈SG)
#include<stdio.h> #include<string.h> #define N 1010 int hash[N]; int sg[N]; void GetSG() ...