URAL 1208 Legendary Teams Contest(DFS)
2016-09-14 18:21
435 查看
Legendary Teams Contest
Time limit: 1.0 secondMemory 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 Klines. 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
Youshould 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 |
【分析】简单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=505; const int M=100005; map<string,int>f; struct node { int a,b,c; } p[20]; int n,maxz; int vis[60]; 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] = 1; dfs(v+1,u+1); vis[p[u].a] = vis[p[u].b] = vis[p[u].c] = 0; } dfs(v,u+1); } int main() { int i,g=0; char s1[22],s2[22],s3[22]; scanf("%d",&n); for(i = 1 ; 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 = 1 ; i <= n ; i++) { vis[p[i].a] = vis[p[i].b] = vis[p[i].c] = 1; dfs(1,i+1); vis[p[i].a] = vis[p[i].b] = vis[p[i].c] = 0; } printf("%d\n",maxz); return 0; }
View Code
相关文章推荐
- URAL 1208 Legendary Teams Contest (DFS)
- 1208. Legendary Teams Contest(dfs)
- 1208. Legendary Teams Contest
- 1208. Legendary Teams Contest
- Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
- URAL 1106 Two Teams (DFS + 二分图)
- ural 1106. Two Teams dfs
- URAL 1106 Two Teams (DFS)
- URAL 1106 Two Teams (DFS)
- Petrozavodsk Summer-2016. Ural FU Dandelion Contest
- URAL 1080 Map Colouring [简单DFS]
- HZAU_1208_color_circle(dfs)
- AtCoder Regular Contest 090 D People on a Line【dfs + bfs】
- ural Pilot Work Experience(dfs + bfs )
- HDU5723 2016 Multi-University Training Contest 1 (最小生成树+dfs)
- URAL 1250. Sea Burial 从问题中抽象出DFS
- URAL 1005 Stone Pile (DFS)
- URAL1329 Galactic History(深搜DFS)
- XDOJ 1208 B.笑爷买房 【DFS】
- UVa 10911 Forming Quiz Teams(dfs)