暴力求解

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

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

#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. 前端学习——JQuery Ajax使用经验

    0.前言     在项目推进过程中常常使用Ajax,通过Jquery提供的函数能够很方便的使用Ajax,可是在实际使用中也遇到一些问题,比如怎样防止浏览器使用缓存,怎样使用同步方式等.通过博文整理总结 ...

  2. 《面试题精选》15.O(logn)求Fibonacci数列

    题目:定义Fibonacci数列例如以下: /    0                      n=0 f(n)=      1                      n=1          ...

  3. C#核编之System.Console类

    顾名思义,Console类封装了基于控制台的输入输出和错误流的操作,下面列举一些System.Console类常用的成员的,这些成员能为简单的命令行程序添加一些"情趣",例如改变背 ...

  4. 基于zepto的手机焦点图touchstart touchmove

    基于zepto的手机焦点图,查看地址:demo (建议使用手机浏览器查看)代码如下: <!DOCTYPE HTML> <html> <head> <title ...

  5. easyui combo自动高度(下拉框空白问题)

    设置.combo-panel {max-height:200px;} 在用到easyui-combobox时,设置panelHeight:'auto'

  6. 清除float常用方法(:after和clear:both)

    参考网址:http://jingyan.baidu.com/article/c74d60006bea410f6a595d17.html .clearfix:after{ .....}  和 .clea ...

  7. 对 PInvoke 函数“WinVideo!WinVideo.webcam::SendMessage”的调用导致堆栈不对称

    从.NET1.1升级到.NET2.0时出现的PInvokeStackImbalance错误微软官方的解释 (http://msdn2.microsoft.com/zh-cn/library/0htdy ...

  8. codevs1304 拓扑序计数

    题目描述                     Description 求一颗有根树/树形图的拓扑序个数. 输入描述                 Input Description        ...

  9. MySQL如何使用索引 较为详细的分析和例子

    在数据库表中,使用索引可以大大提高查询速度. 假如我们创建了一个 testIndex 表: CREATE TABLE testIndex(i_testID INT NOT NULL,vc_Name V ...

  10. iOS Code Sign error

    出现上述错误,检查是否是证书添加错误