暴力求解

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

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

#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. rem详解

    rem这是个低调的css单位,近一两年开始崭露头角,有许多同学对rem的评价不一,有的在尝试使用,有的在使用过程中遇到坑就弃用了.但是我对rem综合评价是用来做web app它绝对是最合适的人选之一. ...

  2. VS2010中查询替换使用

    MSDN:http://msdn.microsoft.com/zh-cn/library/afy96z92.aspx 例子:

  3. C++ Primer 读书笔记:第11章 泛型算法

    第11章 泛型算法 1.概述 泛型算法依赖于迭代器,而不是依赖容器,需要指定作用的区间,即[开始,结束),表示的区间,如上所示 此外还需要元素是可比的,如果元素本身是不可比的,那么可以自己定义比较函数 ...

  4. 多主一从mysql replication同步表的大胆尝试.

    能否将不同机器上的不同库中的表同步到同一个机器的同一个库中?表是不同的.而且对于slave这台机子来说,这些表只用来读.   同步不同库的表很简单了,用 replicate-do-table=db_n ...

  5. linux 生产环境搭建

    Linux基础命令杂记   今天又一次搞Linux生产环境搭建.这是种步骤很多,很繁琐而且又不得不做的事情.虽然做过很多次,但还是有很多步骤.命令不记得,每一次到处找资料很麻烦,于是将一些步骤记下,以 ...

  6. 如何编写Dll(用命令行编译加深理解)

    DLL的优点 简单的说,dll有以下几个优点: 1)      节省内存.同一个软件模块,若是以源代码的形式重用,则会被编译到不同的可执行程序中,同时运行这些exe时这些模块的二进制码会被重复加载到内 ...

  7. 一种基于Qt的可伸缩的全异步C/S架构服务器实现(流浪小狗,六篇,附下载地址)

    本文向大家介绍一种基于Qt的伸缩TCP服务实现.该实现针对C/S客户端-服务集群应用需求而搭建.连接监听.数据传输.数据处理均在独立的线程池中进行,根据特定任务不同,可安排负责监听.传输.处理的线程数 ...

  8. 关于“创业者与VC见面的10个不成文细节点”

    著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:Will Wang链接:http://www.zhihu.com/question/19641135/answer/50974 ...

  9. android 向SD卡写入数据

    原文:android 向SD卡写入数据 1.代码: /** * 向sdcard中写入文件 * @param filename 文件名 * @param content 文件内容 */ public v ...

  10. mssql中得到当天数据的语句

    一条例子: 关键语句: