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 ...
随机推荐
- 打造XP下可运行的微型PE文件
前几天和朋友交流技术,提到手工打造微型PE文件,他说现在网上流传的大部分版本在XP SP3下都不能运行,于是心血来潮,拍着胸脯说:“你放心,忙完了帮你做一个.”后来花了半天时间,终于打造出一个XP下可 ...
- C编译错误解决方法
1.expected identifier before numeric constant 一般情况下是枚举类型中的某个变量已经被#define定义过一次了,在项目空间中搜索你枚举类型中的所有变量类型 ...
- 2014 ACM/ICPC Asia Regional Xi'an Online Paint Pearls
传说的SB DP: 题目 Problem Description Lee has a string of n pearls. In the beginning, all the pearls have ...
- Asp.Net中用JS中操作cookie的方法
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cookies.aspx.cs& ...
- Python Tricks 若干
赵斌 - APRIL 29, 2015 在 python 代码中可以看到一些常见的 trick,在这里做一个简单的小结. json 字符串格式化 在开发 web 应用的时候经常会用到 json 字符串 ...
- 单选项框RadioGroup的综合应用
大家好,我们今天这一节要介绍的是RadioGroup 的组事件.RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只 ...
- C#中String跟string的“区别”
string是c#中的类,String是.net Framework的类(在C# IDE中不会显示蓝色) C# string映射为.net Framework的String 如果用string,编译器 ...
- 编程实现linux下的shell
/************************************************************************* > File Name: Kris_shel ...
- BZOJ 1296: [SCOI2009]粉刷匠 分组DP
1296: [SCOI2009]粉刷匠 Description windy有 N 条木板需要被粉刷. 每条木板被分为 M 个格子. 每个格子要被刷成红色或蓝色. windy每次粉刷,只能选择一条木板上 ...
- 【转载】 硬盘主引导记录(MBR)及其结构详解
硬盘的0柱面.0磁头.1扇区称为主引导扇区,FDISK程序写到该扇区的内容称为主引导记录(MBR).该记录占用512个字节,它用于硬盘启动时将系统控制权交给用户指定的,并在分区表中登记了的某个操作系统 ...