题目2 : 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.

样例输入
  1. 2
  2. abcdefg
  3. zaxcdkgb
  4. 5
  5. abcdef
  6. kedajceu
  7. adbac
  8. abcdef
  9. abcdafc
  10. 2
  11. abc
  12. def
样例输出
  1. acdg
  2. acd
  3. 0
  4.  
  1. #include<bits/stdc++.h>
  2. #define MAX 15
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. string s[MAX];
  7. int n;
  8. string ss,ans;
  9.  
  10. int find(string x){
  11. int lenx=x.length();
  12. for(int i=;i<n;i++){
  13. int len=s[i].length();
  14. int f=;
  15. for(int k=;k<len;k++){
  16. if(s[i][k]==x[]){
  17. int c=;int l=-;
  18. for(int j=k;j<len;j++){
  19. if(s[i][j]==x[c]){
  20. if(l==-) l=j;
  21. c++;
  22. if(c>=lenx&&(j-l+)<=(len/)){
  23. f=;
  24. break;
  25. }
  26. }
  27. }
  28. if(f==) break;
  29. }
  30. }
  31. if(f==) return ;
  32. }
  33. return ;
  34. }
  35. void dfs(int en,string x,int st){
  36. if(st>=en){
  37. if(find(x)==){
  38. if(x.length()>ans.length()){
  39. ans=x;
  40. }
  41. else if(x.length()==ans.length()){
  42. if(x<ans){
  43. ans=x;
  44. }
  45. }
  46. }
  47. return;
  48. }
  49. for(int i=;i<=;i++){
  50. if(i==) dfs(en,x+ss[st],st+);
  51. else dfs(en,x,st+);
  52. }
  53. }
  54. int main()
  55. {
  56. int t,i,j;
  57. while(~scanf("%d",&n)){
  58. for(i=;i<n;i++){
  59. cin>>s[i];
  60. s[i]+=s[i];
  61. }
  62. ans="{";
  63. int len=s[].length();
  64. for(i=;i<len;i++){
  65. int minn=min(len-i,len/);
  66. for(j=;j<=minn;j++){
  67. ss=s[].substr(i,j);
  68. dfs(j,"",);
  69. }
  70. }
  71. if(ans=="{") printf("0\n");
  72. else cout<<ans<<endl;
  73. }
  74. return ;
  75. }

ACM-ICPC2018北京网络赛 Tomb Raider(暴力)的更多相关文章

  1. acm 2015北京网络赛 F Couple Trees 树链剖分+主席树

    Couple Trees Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/123 ...

  2. acm 2015北京网络赛 F Couple Trees 主席树+树链剖分

    提交 题意:给了两棵树,他们的跟都是1,然后询问,u,v 表 示在第一棵树上在u点往根节点走 , 第二棵树在v点往根节点走,然后求他们能到达的最早的那个共同的点 解: 我们将第一棵树进行书链剖,然后第 ...

  3. hihocoder1236(北京网络赛J):scores 分块+bitset

    北京网络赛的题- -.当时没思路,听大神们说是分块+bitset,想了一下发现确实可做,就试了一下,T了好多次终于过了 题意: 初始有n个人,每个人有五种能力值,现在有q个查询,每次查询给五个数代表查 ...

  4. 2015北京网络赛 D-The Celebration of Rabbits 动归+FWT

    2015北京网络赛 D-The Celebration of Rabbits 题意: 给定四个正整数n, m, L, R (1≤n,m,L,R≤1000). 设a为一个长度为2n+1的序列. 设f(x ...

  5. 2015北京网络赛 J Scores bitset+分块

    2015北京网络赛 J Scores 题意:50000组5维数据,50000个询问,问有多少组每一维都不大于询问的数据 思路:赛时没有思路,后来看解题报告也因为智商太低看了半天看不懂.bitset之前 ...

  6. 2015北京网络赛 Couple Trees 倍增算法

    2015北京网络赛 Couple Trees 题意:两棵树,求不同树上两个节点的最近公共祖先 思路:比赛时看过的队伍不是很多,没有仔细想.今天补题才发现有个 倍增算法,自己竟然不知道.  解法来自 q ...

  7. HDU-4041-Eliminate Witches! (11年北京网络赛!!)

    Eliminate Witches! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  8. Tomb Raider(暴力模拟)

    Tomb Raider https://hihocoder.com/problemset/problem/1829?sid=1394836 时间限制:1000ms 单点时限:1000ms 内存限制:2 ...

  9. hihoCoder-1829 2018亚洲区预选赛北京赛站网络赛 B.Tomb Raider 暴力 字符串

    题面 题意:给你n个串,每个串都可以选择它的一个长度为n的环形子串(比如abcdf的就有abcdf,bcdfa,cdfab,dfabc,fabcd),求这个n个串的这些子串的最长公共子序列(每个串按顺 ...

随机推荐

  1. 九度OJ 1042:Coincidence(公共子序列) (DP)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2303 解决:1241 题目描述: Find a longest common subsequence of two strings. 输入 ...

  2. samba服务器的搭建和配置

    案例: 公司有两个部门, sales / market . 分别有成员 jack / tom 和 zhang / shen . 公司需求是这样的, 本部门资料禁止其他部门访问, 本部门成员之间不能干扰 ...

  3. uboot 2013.01 s3c6400编译失败

    通常我们对s3c6410平台开发u-boot是在s3c6400的基础上修改而成的,但是从uboot 2013.01这个版本之后的版本都把smdk6400对应的配置给删除了. 这是因为该版本smdk64 ...

  4. linux系统调用mount全过程分析【转】

    本文转载自:https://blog.csdn.net/skyflying2012/article/details/9748133 系统调用本身是软中断,使用系统调用,内核也陷入内核态,异常处理,找到 ...

  5. poj 1146 ID Codes (字符串处理 生成排列组合 生成当前串的下一个字典序排列 【*模板】 )

    ID Codes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6229   Accepted: 3737 Descript ...

  6. [转] 中国压缩传感资源(China Compressive Sensing Resources)

    昨天查压缩感知的资料,无意间看到一位浙大女神Rachel Zhang的博客,果断关注了.我感觉应该向她好好学习.下面转自她的CSDN博客.网址是http://blog.csdn.net/abcjenn ...

  7. LNMP搭建随笔

    LNMP(即Linux+Nginx+MYSQL+PHP)是目前非常热门的动态网站部署架构,一般是指: Linux:如RHEL.Centos.Debian.Fedora.Ubuntu等系统. Nginx ...

  8. PYTHON 爬虫笔记六:PyQuery库基础用法

    知识点一:PyQuery库详解及其基本使用 初始化 字符串初始化 html = ''' <div> <ul> <li class="item-0"&g ...

  9. hdmap相关单词

    交叉口(junction) 交叉口组(junctiongroup)

  10. 分享知识-快乐自己:SpringMvc中 页面日期格式到后台的类型转换

    日期格式的类型转换: 以往在 from 表单提交的时候,都会有字符串.数字.还有时间格式等信息. 往往如果是数字提交的话底层会自动帮我们把类型进行了隐式转换. 但是日期格式的却不能自动转换,这就需要我 ...