URAL 1208 Legendary Teams Contest(DFS)
Legendary Teams Contest
Memory limit: 64 MB
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…
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
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
should output the maximal possible number of legendary teams of
veterans, that could simultaneously participate at the contest.
Sample
input | output |
---|---|
7 |
4 |
#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)的更多相关文章
- 1208. Legendary Teams Contest(dfs)
1208 简单dfs 对于每个数 两种情况 取还是不取 #include <iostream> #include<cstdio> #include<cstring> ...
- ural 1208 Legendary Teams Contest
题意描述:给定K支队伍,每队三个队员,不同队伍之间队员可能部分重复,输出这些队员同时能够组成多少完整的队伍: DFS,利用DFS深度优先搜索,如果该队所有队员都没有被访问过,那么将该队计入结果,再去选 ...
- POJ 3660 Cow Contest (dfs)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11129 Accepted: 6183 Desc ...
- LeetCode Subsets II (DFS)
题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...
- LeetCode Subsets (DFS)
题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...
- HDU 2553 N皇后问题(dfs)
N皇后问题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 在 ...
- 深搜(DFS)广搜(BFS)详解
图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...
- 【算法导论】图的深度优先搜索遍历(DFS)
关于图的存储在上一篇文章中已经讲述,在这里不在赘述.下面我们介绍图的深度优先搜索遍历(DFS). 深度优先搜索遍历实在访问了顶点vi后,访问vi的一个邻接点vj:访问vj之后,又访问vj的一个邻接点, ...
- 深度优先搜索(DFS)与广度优先搜索(BFS)的Java实现
1.基础部分 在图中实现最基本的操作之一就是搜索从一个指定顶点可以到达哪些顶点,比如从武汉出发的高铁可以到达哪些城市,一些城市可以直达,一些城市不能直达.现在有一份全国高铁模拟图,要从某个城市(顶点) ...
随机推荐
- Program B 暴力求解
Given a sequence of integers S = {S1,S2,...,Sn}, you should determine what is the value of the maxim ...
- matlab函数调用及数据传递
http://www.cnblogs.com/duanp/archive/2008/11/29/Matlab-GUIDE.html函数调用 在一个m文件中,可以定义多个函数,但是文件名一定要与第一个函 ...
- PHP及Javascript 正则判断中文(转)
UTF-8匹配: 在javascript中,要判断字符串是中文是很简单的.比如: var str = "php编程"; if (/^[\u4e00-\u9fa5]+$/.test( ...
- Javascript使用总结
Javascript(简称JS)简介 JavaScript是一门广泛用于浏览器客户端的脚本语言,由Netspace公司设计,当时跟Sun公司(已经被oracle收购)合作,所以名字起得像Java,业内 ...
- javascript中创建对象的几种方式
1. 使用Object构造函数来创建一个对象,下面代码创建了一个person对象,并用两种方式打印出了Name的值. var person = new Object(); person.name=&q ...
- 立体透视 perspective transform-style 倾斜旋转
1.perspective 是设置镜头距离,距离越远视图越小,视图越近,视图越大.就像相机焦距一样.其只对子元素产生效果. 2.transform-style: preserve-3d 设置3d效果, ...
- 生成1~n的全排列
输入正整数n,输出n的全排列. 样例输入1: 3 样例输出1: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 分析: 按字典序从小到大的顺序输出所有的排列. (字典序:两个序 ...
- eclipse安卓模拟器窗口大小调整
引自百度经验的链接: http://jingyan.baidu.com/article/3aed632e18c7e97011809161.html
- php大力力 [009节]php在百度文库的几个基础教程
2015-08-23 php大力力009. php在百度文库的几个基础教程 php大力力 [009节]php在百度文库的几个基础教程 PHP脚本中操作MySQL数据库3-猿代码平台 php基础教程-绝 ...
- 又见蒙特卡洛——python模拟解决三门问题
三门问题很有意思,wiki用不同方法将原理讲的很透彻了,我跟喜欢其中这种理解方式:无论参赛者开始的选择如何,在被主持人问到是否更换时都选择更换.如果参赛者先选中山羊,换之后百分之百赢:如果参赛者先选中 ...