时间限制:1000ms

单点时限:1000ms

内存限制:256MB

描述

Lara Croft, the fiercely independent daughter of a missing adventurer, must push herself beyond her limits when she discovers the island where her father disappeared. In this mysterious island, Lara finds a tomb with a very heavy door. To open the door, Lara must input the password at the stone keyboard on the door. But what is the password? After reading the research notes written in her father's notebook, Lara finds out that the key is on the statue beside the door.

The statue is wearing many arm rings on which some letters are carved. So there is a string on each ring. Because the letters are carved on a circle and the spaces between any adjacent letters are all equal, any letter can be the starting letter of the string. The longest common subsequence (let's call it "LCS") of the strings on all rings is the password. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

For example, there are two strings on two arm rings: s1 = "abcdefg" and s2 = "zaxcdkgb". Then "acdg" is a LCS if you consider 'a' as the starting letter of s1, and consider 'z' or 'a' as the starting letter of s2. But if you consider 'd' as the starting letter of s1 and s2, you can get "dgac" as a LCS. If there are more than one LCS, the password is the one which is the smallest in lexicographical order.

Please find the password for Lara.

输入

There are no more than 10 test cases.

In each case:

The first line is an integer n, meaning there are n (0 < n ≤ 10) arm rings.

Then n lines follow. Each line is a string on an arm ring consisting of only lowercase letters. The length of the string is no more than 8.

输出

For each case, print the password. If there is no LCS, print 0 instead.

样例输入

2
abcdefg
zaxcdkgb
5
abcdef
kedajceu
adbac
abcdef
abcdafc
2
abc
def

样例输出

acdg
acd
0

数据量非常小,根本用不到什么算法,暴搜出每一个字符串的所有子序列,每一个字符串的所有子序列加入一个set里,最后求n个set的交集中最长的那个字符串字典序最小的即可

#include <bits/stdc++.h>
using namespace std;
set<string> st[11];
string t,ans;
int len;
void dfs(int i,int cur)
{if(cur == len) {if(ans == "") return;st[i].insert(ans);int _len = ans.length();for(int j = 1; j < _len; j++) {st[i].insert(ans.substr(j,len - j) + ans.substr(0,j));}return;}for(int j = 0; j <= 1; j++) {if(j == 0) ans.push_back(t[cur]);dfs(i,cur + 1);if(j == 0) ans.erase(ans.end() - 1);}
}
int main(void)
{int n;while(scanf("%d",&n) != EOF) {for(int i = 0; i < n; i++) {st[i].clear();}for(int i = 0; i < n; i++) {cin >> t;len = t.length();dfs(i,0);}set<string>::iterator it;string ans = "0";int flag;for(it = st[0].begin(); it != st[0].end(); it++) {t = *it;flag = 0;for(int i = 1; i < n; i++) {if(!st[i].count(t)) {flag = 1;break;}}if(flag == 0) {if(ans == "0") {ans = t;}else if(t.length() > ans.length()) {ans = t;}else if(t.length() == ans.length() && ans > t) {ans = t;}}}cout << ans << endl;}return 0;
}

ACM-ICPC 2018 北京赛区网络预赛 Tomb Raider(暴力)相关推荐

  1. ACM-ICPC 2018 北京赛区网络预赛(A B C D H)

    ACM-ICPC 2018 北京赛区网络预赛(A B C D H) 自闭症患者 A. Saving Tang Monk II 题目链接 题面: 划掉 题意: 大搜索,队友写的 思路: 大搜索,队友写的 ...

  2. ICPC 2018 焦作赛区网络预赛G Give Candies 组合数学隔板法+欧拉降幂

    G Give Candies 计蒜客 G Give Candies 题意 n n n个糖果, n n n个人从 1 1 1~ n n n编号,每次给一个人发糖可以发任意数量但不能小于 1 1 1,直到 ...

  3. ACM-ICPC 2018 南京赛区网络预赛

    轻轻松松也能拿到区域赛名额,CCPC真的好难 An Olympian Math Problem 问答 只看题面 54.76% 1000ms 65536K Alice, a student of gra ...

  4. ACM-ICPC 2018 焦作赛区网络预赛 J(二分+JAVA高精)

    传送门 题面: 65536K Jessie and Justin want to participate in e-sports. E-sports contain many games, but t ...

  5. ACM-ICPC 2018 沈阳赛区网络预赛 Spare Tire(容斥+公式推)

    A sequence of integer \lbrace a_n \rbrace{an​} can be expressed as: \displaystyle a_n = \left\{ \beg ...

  6. ACM-ICPC 2018 徐州赛区网络预赛 Features Track(STL二维map)

    Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 D. Easy Math

    Easy Math 问答问题反馈 只看题面 16.47% 1000ms 262144K Given a positive integers nn , Mobius function \mu(n)μ(n ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 D. EasyMath

    ACM-ICPC 2018 徐州赛区网络预赛 D. EasyMath 做法: \[f(m,n) = \sum _{i=1}^{m} \mu(in) = \sum_{i=1}^{m}[gcd(i,n)= ...

  9. ACM-ICPC 2018 焦作赛区网络预赛 H题 String and Times(SAM)

    Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring won ...

  10. ACM-ICPC 2018 徐州赛区网络预赛G (单调队列)

    传送门 题面: There's a beach in the first quadrant. And from time to time, there are sea waves. A wave (  ...

最新文章

  1. 安装centos 7 桌面
  2. Keras vs PyTorch,哪一个更适合做深度学习?
  3. CodeForces - 1029B.Creating the Contest(最长上升子序列0(n)解法)
  4. 08.认证考试注意事项
  5. oracle4.0,OracleTM Application Server 4.0简 介
  6. python文件夹目录_Python 操作文件、文件夹、目录大全
  7. iOS开发之SQLite的Object-C封装
  8. Python 机器学习经典实例
  9. Topaz Plugins Bundle 2018 for Mac(PS插件滤镜特效包)
  10. SpringBoot整合支付宝APP支付
  11. openresty模板html页面,springboot+nginx+lua开发+html模板渲染
  12. T00ls技术文章.rar
  13. 华硕B85 pro gamer +i5 4590 +GTX960 成功安装黑苹果 macOS 10.12.2
  14. 关于include的正确理解和用法
  15. 我给鸿星尔克写了一个720°全景看鞋展厅
  16. 百度TV运营商随视传媒发布新广告平台AdMan
  17. 2021icpc网络赛
  18. 牛批!Alibaba内部学习指南+最新面试题+学习大纲+内部学习书籍,理论与实战双管齐下!
  19. java oop6_Java oop代码6(原创方法):5道用上extends继承,子类,父类的题
  20. 80x86编程手册_编程从8到80

热门文章

  1. linux affinity,Linux CPU Affinity
  2. 将图片中的公式转化为latex代码(image to latex)。两种方法:python包或者snip软件
  3. SpringBoot 如何执行定时任务
  4. 解决宏碁5750g ubuntu无法调整和保存屏幕亮度的问题
  5. nec编码红外遥控原理整理
  6. input()函数的简单介绍
  7. 推动铅蓄电池绿色“转身”
  8. Ubuntu 16.04 LTS 完善解决亮度调整
  9. DSP Bootloader说明
  10. 如何用定积分求椭圆的周长_怎么用微积分求椭圆的周长?