Legendary Teams Contest

Time limit: 1.0 second
Memory limit: 64 MB
Nothing
makes as old as years. A lot of cool contests are gone, a lot of
programmers are not students anymore and are not allowed to take part at
the contests. Though their spirit is fresh and young as it was years
ago! And so once they decided to make a contest at the Ural State
University among the veteran teams…
To
make the contest interesting, they decided to invite as much
"legendary" teams as possible. The jury has made a short list of teams,
which have shown the best results in the old good times, thus being
worthy to hold the name of "legendary". All those teams were invited to
take part of the contest, and all of them accepted the invitations. But
they have forgotten one important thing at the jury: during the long
history of the contests at the university, the teams happened to change
and some programmers managed to contest in different "legendary" teams.
Though, the jury decided not to give up the initial idea and to form as
much legendary teams as possible to participate at the contest — and
your program should help the jury!

Input

The first line contains a positive integer K, 1 ≤ K ≤ 18. It is the number of all the legendary teams. There follow the descriptions of the teams in K
lines. Each of those lines contains three names of the team members of
the respective team. All names are written with not more than 20 small
Latin letters.

Output

You
should output the maximal possible number of legendary teams of
veterans, that could simultaneously participate at the contest.

Sample

input output
7
gerostratos scorpio shamgshamg
zaitsev silverberg cousteau
zaitsev petersen shamgshamg
clipper petersen shamgshamg
clipper bakirelli vasiliadi
silverberg atn dolly
knuth dijkstra bellman
4
Problem Author: Leonid Volkov
【分析】简单dfs.

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define inf 0x3f3f3f3f
#define mod 10000
typedef long long ll;
using namespace std;
const int N=;
const int M=;
map<string,int>f;
struct node {
int a,b,c;
} p[];
int n,maxz;
int vis[]; void dfs(int v,int u) {
maxz = max(maxz,v);
if(u>n)
return ;
if(!vis[p[u].a]&&!vis[p[u].b]&&!vis[p[u].c]) {
vis[p[u].a] = vis[p[u].b] = vis[p[u].c] = ;
dfs(v+,u+);
vis[p[u].a] = vis[p[u].b] = vis[p[u].c] = ;
}
dfs(v,u+);
}
int main() {
int i,g=;
char s1[],s2[],s3[];
scanf("%d",&n);
for(i = ; i <= n ; i++) {
scanf("%s%s%s",s1,s2,s3);
if(!f[s1])f[s1] = ++g;
if(!f[s2])f[s2] = ++g;
if(!f[s3])f[s3] = ++g;
p[i].a = f[s1];
p[i].b = f[s2];
p[i].c = f[s3];
}
for(i = ; i <= n ; i++) {
vis[p[i].a] = vis[p[i].b] = vis[p[i].c] = ;
dfs(,i+);
vis[p[i].a] = vis[p[i].b] = vis[p[i].c] = ;
}
printf("%d\n",maxz);
return ;
}

URAL 1208 Legendary Teams Contest(DFS)的更多相关文章

  1. 1208. Legendary Teams Contest(dfs)

    1208 简单dfs 对于每个数 两种情况 取还是不取 #include <iostream> #include<cstdio> #include<cstring> ...

  2. ural 1208 Legendary Teams Contest

    题意描述:给定K支队伍,每队三个队员,不同队伍之间队员可能部分重复,输出这些队员同时能够组成多少完整的队伍: DFS,利用DFS深度优先搜索,如果该队所有队员都没有被访问过,那么将该队计入结果,再去选 ...

  3. POJ 3660 Cow Contest (dfs)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11129   Accepted: 6183 Desc ...

  4. LeetCode Subsets II (DFS)

    题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...

  5. LeetCode Subsets (DFS)

    题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...

  6. HDU 2553 N皇后问题(dfs)

    N皇后问题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 在 ...

  7. 深搜(DFS)广搜(BFS)详解

    图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...

  8. 【算法导论】图的深度优先搜索遍历(DFS)

    关于图的存储在上一篇文章中已经讲述,在这里不在赘述.下面我们介绍图的深度优先搜索遍历(DFS). 深度优先搜索遍历实在访问了顶点vi后,访问vi的一个邻接点vj:访问vj之后,又访问vj的一个邻接点, ...

  9. 深度优先搜索(DFS)与广度优先搜索(BFS)的Java实现

    1.基础部分 在图中实现最基本的操作之一就是搜索从一个指定顶点可以到达哪些顶点,比如从武汉出发的高铁可以到达哪些城市,一些城市可以直达,一些城市不能直达.现在有一份全国高铁模拟图,要从某个城市(顶点) ...

随机推荐

  1. MonoRail学习-入门实例篇

    1.到官方网站下载安装文件,地址如下: http://www.castleproject.org/index.php/Castle:Download目前最新版本Beta5(您也可以不需要下载,直接使用 ...

  2. matlab图形句柄属性总结

    原文在于雪漫的bloghttp://blog.sina.com.cn/s/blog_4b9b714a0100cce2.html这两天在看句柄式图形方面的东西,以下是我在看书过程中整理的学习笔记,比较详 ...

  3. php中的include()的使用技巧

    php中的include()的使用技巧 include() 语句包括并运行指定文件. 以下文档也适用于 require().这两种结构除了在如何处理失败之外完全一样.include() 产生一个警告而 ...

  4. (转)关于java和web项目中的相对路径问题

    原文:http://blog.csdn.net/yethyeth/article/details/1623283 关于java和web项目中的相对路径问题 分类: java 2007-05-23 22 ...

  5. hdu 2070

    ps:...递推..还是给出公式那种... 代码: #include "stdio.h" #define LL long long LL dp[]; int main(){ int ...

  6. BZOJ 2083 Intelligence test

    用vector,二分. #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  7. 查询某个表或者所有表的字段说明 SQLServer

    查询某个表或者所有表的字段说明SELECT    [Table Name] = OBJECT_NAME(c.object_id),    [Column Name] = c.name,    [Des ...

  8. jqGrid详解及高级应用(十四)

    一:jqGrid 是一个用来显示网格数据的jQuery插件,文档比较全面,附带中文版本.  二:官方主页http://www.jqgrid.com/目前最新版本:jqGrid 3.7 Beta在线文档 ...

  9. GETorPOST方式保存和获取图片信息

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  10. [SYSU]每周一赛

    2014年每周一赛第一场 A.Cutting Sausages                                        B.Rectangular Fields //待做    ...