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. C# 轉義字符

    转义字符 意义 ASCII码值(十进制) \a 响铃(BEL) 007 \b 退格(BS) ,将当前位置移到前一列 008 \f 换页(FF),将当前位置移到下页开头 012 \n 换行(LF) ,将 ...

  2. 恢复drop数据

    select * from recyclebin r where r.original_name = 'MSM_EXAINVITEBIDSCHEMEHEAD' ; flashback table MS ...

  3. APP store 上架过程中碰到的那些坑&被拒的各种奇葩原因整理&审核指南中文版

    苹果官方发布的十大常见被拒原因 1.崩溃次数和Bug数量.苹果要求开发者在将应用提交给App Store之前彻查自己的应用,以尽量避免Bug的存在. 2.链或错误的链接.应用中所有的链接必须是真实且有 ...

  4. Windows Azure 实操 —— 迁移本地SharePoint服务器到Azure

    博客地址 http://blog.csdn.net/foxdave 注意:如果你是第二代虚拟机,那就别看这个了,老老实实在Azure上重新创建吧,Azure不支持第二代虚拟机. 写在之前,对Azure ...

  5. hdu4283 区间dp

    //Accepted 300 KB 0 ms //区间dp //dp[i][j] 表示i到j第一个出场的最小diaosizhi //对于i到j考虑元素i //(1)i第一个出场,diaosizhi为 ...

  6. iOS开发经验总结(转)

    在iOS开发中经常需要使用的或不常用的知识点的总结,几年的收藏和积累(踩过的坑). 一. iPhone Size 手机型号 屏幕尺寸 iPhone 4 4s 320 * 480 iPhone 5 5s ...

  7. 转 15款免费WiFi(入侵破解)安全测试工具

    转:http://www.ctocio.com/security/cloudsecurity/6594.html 一.Vistumbler扫描器 WiFi 扫描器能能发现附近AP的详细信息,例如信号强 ...

  8. js面向对象(构造函数与继承)

    深入解读JavaScript面向对象编程实践 Mar 9, 2016 面向对象编程是用抽象方式创建基于现实世界模型的一种编程模式,主要包括模块化.多态.和封装几种技术. 对JavaScript而言,其 ...

  9. spark与Hadoop区别

    2分钟读懂Hadoop和Spark的异同 2016.01.25 11:15:59 来源:51cto作者:51cto ( 0 条评论 )   谈到大数据,相信大家对Hadoop和Apache Spark ...

  10. 数据结构 《2》----基于邻接表表示的图的实现 DFS(递归和非递归), BFS

    图通常有两种表示方法: 邻接矩阵 和 邻接表 对于稀疏的图,邻接表表示能够极大地节省空间. 以下是图的数据结构的主要部分: struct Vertex{ ElementType element; // ...