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 ...
随机推荐
- 【转载】C++——CString用法大全
CString常用方法简介 作者:webmaster 出处:无 CString::Compareint Compare( LPCTSTR lpsz ) const;返回值 字符串一样 返回0 ...
- Codeforces Round #263 (Div. 2)
吐槽:一辈子要在DIV 2混了. A,B,C都是简单题,看AC人数就知道了. A:如果我们定义数组为N*N的话就不用考虑边界了 #include<iostream> #include &l ...
- Python:异常处理
Python 是面向对象的语言,所以程序抛出的异常也是类. 一.常见的异常类 NameError:尝试访问一个没有申明的变量 ZeroDivisionError:除数为 0 SyntaxError:语 ...
- Sqli-labs less 62
此处union和报错注入都已经失效了,那我们就要使用延时注入了,此处给出一个示例 payload: http://127.0.0.1/sqli-labs/Less-62/?id=1%27)and%20 ...
- 用linux服务器下的/dev/shm/来释放磁盘的压力
巧用linux服务器下的/dev/shm/来释放磁盘的压力 浏览:646 | 更新:2013-06-18 18:08 | 标签: 磁盘 tmpfs是Linux/Unix系统上的一种基于内存的文件系统. ...
- HDU 1796 How many integers can you find (状态压缩 + 容斥原理)
题目链接 题意 : 给你N,然后再给M个数,让你找小于N的并且能够整除M里的任意一个数的数有多少,0不算. 思路 :用了容斥原理 : ans = sum{ 整除一个的数 } - sum{ 整除两个的数 ...
- 2014多校第四场1005 || HDU 4901 The Romantic Hero (DP)
题目链接 题意 :给你一个数列,让你从中挑选一些数组成集合S,挑另外一些数组成集合T,要求是S中的每一个数在原序列中的下标要小于T中每一个数在原序列中下标.S中所有数按位异或后的值要与T中所有的数按位 ...
- js之数组常见的方法
主要介绍数组的一些常用的方法,方法多了,就容易混淆,结果就是方法用错,甚至不会用: 一.数组的定义: 1.字面量/直接量: var arr = [1, 2, 'js', 'java']; 2.通过内部 ...
- 李洪强漫谈iOS开发[C语言-006]-程序的描述方式
- lintcode:两数组的交 II
题目 计算两个数组的交 注意事项 每个元素出现次数得和在数组里一样答案可以以任意顺序给出 样例 nums1 = [1, 2, 2, 1], nums2 = [2, 2], 返回 [2, 2]. 解题 ...