#1829 : Tomb Raider

时间限制: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
#include<bits/stdc++.h>
using namespace std;#define e exp(1)
#define pi acos(-1)
#define mod 998244353
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}int n,flag;
string s;
map<string,int> m,vis;
vector<string> v;
string sub(int x)
{string index=s.substr(x);index+=s.substr(0,x);return index;
}
bool cmp(string a,string b)
{if(a.length()==b.length())return a<b;return a.length()>b.length();
}
int main()
{while(~scanf("%d",&n)){m.clear();v.clear();flag=0;for(int cas=0; cas<n; cas++){cin>>s;int len=s.length();for(int l=0; l<len; l++){string s1=sub(l);for(int i=1; i<(1<<len); i++){string s2;for(int j=0; j<len; j++){if((1<<j)&i)s2+=s1[j];}if(vis[s2]==0){m[s2]++;vis[s2]=1;}}}vis.clear();}for(map<string,int>::iterator i=m.begin(); i!=m.end(); i++){if(i->second==n){v.push_back(i->first);flag=1;}}sort(v.begin(), v.end(), cmp);if(flag==0)puts("0");else cout<<v[0]<<endl;}return 0;
}

ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 Tomb Raider(map+二进制枚举)相关推荐

  1. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 【bfs + 记忆化搜索 + 剪枝】 AC 代码

    ACM 北京区域赛 bfs+剪枝+ms 第一个一遍过的题目,基本没有看题解 记忆搜索当中,注意初始化成一个特殊值:而在访问之后,每个点就会有一个不同于INF(或者 -1等特殊标记)的值 先到先得,适者 ...

  2. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days(双向队列+尺取法)

    #1831 : 80 Days 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 80 Days is an interesting game based on Jules ...

  3. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 D【队列】

    #1831 : 80 Days 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 80 Days is an interesting game based on Jules ...

  4. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 D. 80 Days

    题解 题目大意 n个点组成一个环形 初始钱为m 从i走到j需要-b[i] + a[j] 要求按照顺时针走完所有的点(不用再回到起点) 过程中m不能小于0 输出最小的起点编号 直接把a[i]和b[i]合 ...

  5. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛

    Saving Tang Monk II Tomb Raider Cheat 80 Days Odd Chess Shortest Path Problem The Mole K-Dimensional ...

  6. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A Saving Tang Monk II【分层bfs】

    时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 <Journey to the West>(also <Monkey>) is one of the ...

  7. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 A. Saving Tang Monk II

    题解 题目大意 给一个图S是起点 T是终点 .是空房间 #是毒气室 B是氧气瓶存放室 P是加速室 每次走到空房间或者起点消耗1秒 走到氧气室获得一个氧气瓶最多携带5个氧气瓶 进入毒气室需要一瓶氧气并且 ...

  8. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 80 Days ——尺取

    描述 80 Days is an interesting game based on Jules Verne's science fiction "Around the World in E ...

  9. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 C-cheat

    超级水的模拟的,我也就会做模拟了--坑有点多,一直没调出来bug,赛后才发现少了一个数字-- 描述 Cheat is a card game played by four players sittin ...

最新文章

  1. swift 中拨电话的实现
  2. windows查看Python安装目录
  3. python的none是什么-python 中None,is和==的深入探讨
  4. 【Android 逆向】Dalvik 函数抽取加壳 ( Dalvik 下的函数指令抽取与恢复 | dex 函数指令恢复时机点 | 类加载流程 : 加载、链接、初始化 )
  5. CUDA学习(三)之使用GPU进行两个数组相加
  6. SVN 如何提交 SO 库文件
  7. How to get list of all public urls which are using BSP UI technology
  8. [导入]如何动态生成table(javascript)
  9. 关于在页面跳转前alert()不能弹出消息的问题
  10. 一次FastDFS并发问题的排查经历
  11. HDU-2819-Swap [二分匹配][输出路径]
  12. java分形_【Java之八】15分钟了解分形之朱利亚集
  13. 群接龙拼团小程序开发
  14. python sample函数取样_Pytorch各种取样器sample
  15. 知识分享!COB封装流程介绍!-道合顺大数据Infinigo
  16. C/C++语言的应用领域
  17. 03基础自绘-05魔法老鼠-magicmouse
  18. 【MPLS】LDP保留的标签
  19. 网络安全之学习方向。
  20. 专利申请的五个步骤介绍

热门文章

  1. 【ElasticSearch】ElasticSearch-SQL插件
  2. 干货!几招教你降低论文重复率!!
  3. Sprint第三阶段(第四天12.12)
  4. 编程方法学18:多维数组收尾
  5. Python学习笔记:‘’AttributeError: NoneType object has no attribute‘’
  6. 高性能计算的线程模型:Pthreads 还是 OpenMP
  7. Android图片适应屏幕大小
  8. 两个年月日怎么相减_会议记录应该怎么记?看这里
  9. 【Python】sort 和 sorted 的用法区别
  10. 科大星云诗社动态20210310