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. POJ 2296 二分+2-sat

    题目大意: 给定n个点,给每个点都安排一个相同的正方形,使这个点落在正方形的下底边的中间或者上底边的中间,并让这n个正方形不出现相互覆盖,可以共享同一条边,求 这个正方形最大的边长 这里明显看出n个点 ...

  2. AIX查看内存卡槽

    1.lscfg -vp|grep Processor 2.lscfg -vp|grep -p Memory

  3. CSS实现图片变灰色及透明度

    [图片变灰] 每当遇到哀悼日,很多网站快速变灰色,来看看实现方式吧: 方式一,仅支持ie) html{filter:progid:DXImageTransform.Microsoft.BasicIma ...

  4. mac终端下运行shell脚本

    最近公司要弄关于IOS下自动化打包的东西,研究了用命令行的形式来代替手工的方式来处理.即: 用xcodebuild 和xcrun  语法来进行脚本实现.    但由于语法的结构够了,另一个问题产生了, ...

  5. 主线程中一定不能放耗时操作,必须要开子线程,比如下载文件,不然会不让你拿到输入流--报错显示android.os.NetworkOnMainThreadException

    1.必须要开子线程来操作耗时操作,android.os.NetworkOnMainThreadException new Thread(new Runnable() { @Override publi ...

  6. 安全攻城狮研发技能栈V1.0,附详细点评~

    2015-12-21 正宗好PT 正宗好PT 今天公司年会,又木有抽到奖,求安慰/(ㄒoㄒ)/~~ 言归正传,我曾经在推特发过一个Skill CheatSheet,被转发和点赞了几百次,我又更新了一下 ...

  7. hdu 2083

    ps:N个数中,中位数是最小距离...第一次WA是因为排序之后最小和最大相加除2...应该是找他们的中位数,而不是中间数. 代码: #include "stdio.h" #incl ...

  8. RFID Hacking①:突破门禁潜入FreeBuf大本营

    某天,偶然间拿到了FreeBuf Pnig0s同学的工卡信息,终于有机会去做一些羞羞的事情了 引子 以下故事纯属虚构,如有雷同,纯属巧合. 我应聘了一个大型IT公司的"网络攻击研究部经理&q ...

  9. IOS开发在线文档 记录下

    View Programming Guide for iOS https://developer.apple.com/library/prerelease/ios/documentation/UIKi ...

  10. swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider

    工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...