http://acm.hdu.edu.cn/showproblem.php?pid=1238

Substrings

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 10   Accepted Submission(s) : 6

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.

Input

The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 100), the number of given strings, followed by n lines, each representing one string of minimum length 1 and maximum length 100. There is no extra white space before and after a string. 

Output

There should be one line per test case containing the length of the largest string found.

Sample Input

2
3
ABCD
BCDFF
BRCD
2
rose
orchid

Sample Output

2
2

直接枚举可能的字串,然后进行验证。

code:

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std; string s[102];
int n;
bool check(string sub) {
int i, j;
string tmp;
for(i=0; i<sub.size(); i++)
tmp +=sub[ sub.size()-1-i];
for(i=0; i<n; i++)
if(s[i].find(sub)==s[i].npos && s[i].find(tmp)==s[i].npos)
return false;
return true;
}
void solve(int t,int p) {
string sub;
int i, j, k;
int ans =0;
for(i=0; i<t; i++)
for(j=t-1; j>=i; j--) {
if(j-i+1<ans) continue;
sub = s[p].substr(i,j-i+1);
if(check(sub)) {
if(j-i+1>ans) ans = j-i+1;
}
}
cout<<ans<<endl;
}
int main() {
// freopen("in.txt","r",stdin);
int T,i,t,sub_i, j;
cin>>T;
while(T--) {
cin>>n;
t = 200;
for(i=0; i<n; i++) {
cin>>s[i];
if(s[i].size()<t) {
t =s[i].size();
sub_i = i;
}
}
solve(t, sub_i);
}
return 0;
}


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 扩展KMP

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

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

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

  4. UVa 12718 Dromicpalin Substrings (暴力)

    题意:给定一个序列,问你它有多少上连续的子串,能够重排后是一个回文串. 析:直接暴力,n 比较小不会超时. 代码如下: #pragma comment(linker, "/STACK:102 ...

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

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

  6. POJ1226 Substrings ——后缀数组 or 暴力+strstr()函数 最长公共子串

    题目链接:https://vjudge.net/problem/POJ-1226 Substrings Time Limit: 1000MS   Memory Limit: 10000K Total ...

  7. Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)

    题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...

  8. Substrings(hdu1238)字符串匹配

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

  9. Java实现 蓝桥杯 算法提高VIP Substrings(暴力)

    试题 算法提高 Substrings 问题描述 You are given a number of case-sensitive strings of alphabetic characters, f ...

随机推荐

  1. centos7连接阿里云长时间连接不上

    一.手动修改网卡配置 手上有几台centos7的linux,当连接阿里云的ecs服务器时候长时间连接不上,最后失败的问题. 使用 -vvv参数到如下语句就卡着不动了 ssh -vvv XXX.XXX. ...

  2. CxGrid 表格列内容居中

    首先每一列 Cxgrid 都不知道要当成什么来出来,所以每一列都有个properties 让你来设置,告诉cxgrid 这列的内容是什么,然后根据你给出的内容 再来决定用什么居中方式: 就是说 官方再 ...

  3. Unix IPC之pipe

    pipe创建函数: #include <unistd.h> /* Create a one-way communication channel (pipe). If successful, ...

  4. Maven3核心技术(笔记三)

    第一节:Maven仓库概念 Maven 远程仓库配置文件:$M2_HOME/lib/maven-model-builder-3.3.3.jar 文件:org\apache\maven\model\po ...

  5. CVE-2013-3346Adobe Reader和Acrobat 内存损坏漏洞分析

    [CNNVD]Adobe Reader和Acrobat 内存损坏漏洞(CNNVD-201308-479) Adobe Reader和Acrobat都是美国奥多比(Adobe)公司的产品.Adobe R ...

  6. hdu 1028 整数划分 (母函数)

    假如输入44 = 4;4 = 3 + 1;4 = 2 + 2;4 = 2 + 1 + 1;4 = 1 + 1 + 1 + 1;一共5种 假如输入3 用母函数的方法就是写成(1+X+X2+X3)(1+X ...

  7. CCF CSP 201412-3 集合竞价

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201412-3 集合竞价 问题描述 某股票交易所请你编写一个程序,根据开盘前客户提交的订单来确 ...

  8. http://localhost/ 或 http://127.0.0.1/ 报错:HTTP 404 的解决办法

    一些初次接触使用 Eclipse 工具来开发 JAVA Web 工程的开发人员,可能会对 Eclipse 和 Tomcat 的绑定产生一个疑惑. 那就是 在修改了 Tomcat 的8080端口为80后 ...

  9. 阿里云ali-oss图片增加水印

    先附上文档连接 : https://helpcdn.aliyun.com/document_detail/44957.html 水印文字或图片必须经过一下转化 URL安全的Base64位编码 在图片处 ...

  10. Hadoop基准测试

    其实就是从网络上copy的吧,在这里做一下记录 这个是看一下有哪些测试方式: hadoop  jar /opt/cloudera/parcels/CDH-5.3.6-1.cdh5.3.6.p0.11/ ...