暴力求解

题意:求一个公共子串的最大长度,反转的公共子串存在也算。

求解思路:先找出最短的字符串进行暴力枚举。每截取一个子串后,求出它的反转字符串,然后检验这两个子字符串是否存在输入的字符串组中,每个字符串只要存在子字符串和的翻转串其中一个就行。

#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
#define max(a,b) a>b?a:b int n,len,id;
string str[];
bool check(string sub)
{
string tmp;
int sl=sub.size();
for(int i=;i<sl;i++)
tmp+=sub[sl--i];
for(int i=;i<n;i++)
if(str[i].find(sub)==str[i].npos && str[i].find(tmp)==str[i].npos)
return false;
return true;
}
void Deal()
{
int ans=;
string tmp;
for(int i=;i<str[id].size();i++)
for(int j=str[id].size()-;j>=i;j--)
{
if((j-i+)<ans) continue;
tmp=str[id].substr(i,j-i+);
if(check(tmp))
ans=max(ans,(j-i+));
}
printf("%d\n",ans);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
len=;
scanf("%d",&n);
for(int i=;i<n;i++)
{
cin>>str[i];
if(str[i].size()<len)
{
len=str[i].size();
id=i;
}
}
Deal();
}
}

hdu1238--Substrings的更多相关文章

  1. HDU-1238 Substrings

    Substrings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  2. hdu1238 Substrings (暴力)

    http://acm.hdu.edu.cn/showproblem.php?pid=1238 Substrings Time Limit : 2000/1000ms (Java/Other)   Me ...

  3. hdu1238 Substrings 扩展KMP

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  4. kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings

    You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...

  5. KMP 、扩展KMP、Manacher算法 总结

    一. KMP 1 找字符串x是否存在于y串中,或者存在了几次 HDU1711 Number Sequence HDU1686 Oulipo HDU2087 剪花布条 2.求多个字符串的最长公共子串 P ...

  6. Substrings(hdu1238)字符串匹配

    Substrings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  7. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  8. Leetcode: Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  9. CSU-1632 Repeated Substrings (后缀数组)

    Description String analysis often arises in applications from biology and chemistry, such as the stu ...

  10. CF451D Count Good Substrings (DP)

    Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...

随机推荐

  1. how to translate the text of push button

    Background:In a project, the need to translate the buttons on the screen, as shown below,the followi ...

  2. magento新闻邮件发送一直处于“正在发送”状态问题解决

    今天在弄magento新闻邮件发送时候发现,单个邮件发送全然没有问题,可是新闻邮件订阅死活都不成功.国内国外的帖子都翻了一遍没实用,最后还是得靠自己了.于是開始慢慢找问题 首先想到是不是crontab ...

  3. Android自己定义组件系列【7】——进阶实践(4)

    上一篇<Android自己定义组件系列[6]--进阶实践(3)>中补充了关于Android中事件分发的过程知识.这一篇我们接着来分析任老师的<可下拉的PinnedHeaderExpa ...

  4. Git 和 SVN之间的五个基本区别

    GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等.如果你是一个具有使用SVN背景的人,你需要做一定的思想转换,来适应GIT提供的一些概念和特征.所以,这篇文章的主要目的就是 ...

  5. poj3461Oulipo

    Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...

  6. MapReduce详解

    1.mapreduce之shuffle http://blog.csdn.net/thomas0yang/article/details/8562910 2.彻底了解mapreduce核心Shuffl ...

  7. skynet的流程1

    logpath = "."harbor = 1address = "127.0.0.1:2526"master = "127.0.0.1:2013&q ...

  8. vs2008调试 Release(链接器来生成调试信息)

    VS2008 Release 修改配置: 1.项目——>属性——>C/ C++ ——> 常规 ——>调试信息格式——>用于“编辑并继续”的程序数据库(/ZI) 2.项目— ...

  9. Delphi下重载窗体CreateParams翻转关闭按钮

    type  TForm1 = class(TForm)  private    { Private declarations }  public    { Public declarations }  ...

  10. 【第一篇章-android平台buffer播放探索】native media

    在android平台,从4.0开始,提出了openmax架构,所以在DNK的R7版本中有了openmax AL层播放的DEMO即native media,这个DEMO就是读本地文件,然后把所读buff ...