暴力求解

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

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

#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. UVA 489-- Hangman Judge(暴力串处理)

     Hangman Judge  In ``Hangman Judge,'' you are to write a program that judges a series of Hangman gam ...

  2. JAVA Socket无参构造方法的使用

    1.Socket类的构造方法很多,只有无参构造方法不会尝试建立连接,其他构造方法,都会尝试建立连接的,如果建立连接失败,将会抛出异常.如果想为Socket设定连接超时时间,此时就需要使用无参构造方法, ...

  3. 初识动画animation

    工作半年了,基本没怎么用到动画,现在对已学到的动画做一个总结(真的非常非常基础啊啊啊),准备之后再慢慢研究一下动画(有好的教程可以推荐给我咩~~). animation animation:mymov ...

  4. UVA1600 Patrol Robot

    题意: 求机器人走最短路线,而且可以穿越障碍.N代表有N行,M代表最多能一次跨过多少个障碍. 分析: bfs()搜索,把访问状态数组改成了3维的,加了个维是当前能跨过的障碍数. 代码: #includ ...

  5. c#创建带参数的线程

    1.无参数线程的创建 Thread thread = new Thread(new ThreadStart(getpic)); thread.Start(); private void showmes ...

  6. Docker终极指南:为什么Docker能做这么多事

    Docker终极指南:为什么Docker能做这么多事 http://www.aboutyun.com/thread-11499-1-1.html

  7. juce 中的WeakReference分析

    juce中的WeakReference设计得比较巧妙,巧妙就是使用delete之后就可以通知道WeakReference,原理其实也很间单,其实就是在对象里添加了一个子对象masterReferenc ...

  8. mklink修改Chrome缓存目录

    管理员命令打开CMDmklink /D "C:\Users\Administrator\AppData\Local\Google\Chrome\User Data" "C ...

  9. Flink Program Guide (8) -- Working with State :Fault Tolerance(DataStream API编程指导 -- For Java)

    Working with State 本文翻译自Streaming Guide/ Fault Tolerance / Working with State ---------------------- ...

  10. Java-Poi 读取excel 数据

    一直想着使用java操作excel,但有时各种原因一直没有实现.由于工作无意间做了个其他demo,为了进一步发散就涉及到了使用excel,为此开始正式接触POI,虽然限制不是很了解POI,但是通过查阅 ...