[KMP或者暴力]POJ 3450 Corporate Identity
来源:互联网 发布:淘宝开店创业计划书 编辑:程序博客网 时间:2024/05/21 23:34
传送门:http://poj.org/problem?id=3450
题目大意:前面那道题类似,求多个字符串的最长且字典序最小的公共子串,还是枚举子串,然后拿去和剩余主串匹配,保存最优解。
代码:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int MAXN = 222,MAXM = 4444;char s[MAXM][MAXN],temp[MAXN],res[MAXN];int next[MAXN],n;void makenext(char *str){ int i = 0,j = -1,M = strlen(str); next[0] = -1; while(i<M){ if(str[i]==str[j]||j==-1)next[++i] = ++j; else j = next[j]; }}int KMP(char *T,char *P){ int N = strlen(T),M = strlen(P),i = 0,j = 0; while(i<N&&j<M){ if(T[i]==P[j]||j==-1)i++,j++; else j = next[j]; } return j==M?i-M:-1;}bool great(char *s1,char *s2){ int l1 = strlen(s1),l2 = strlen(s2); if(l1!=l2)return l1>l2; return strcmp(s1,s2)<0;}int main(){ while(scanf("%d",&n),n){ for(int i=0;i<n;i++)scanf("%s",s[i]); int l = strlen(s[0]);res[0] = 0; for(int i=0;i<l;i++){ for(int j=i;j<l;j++){ for(int k=0;k<j-i+1;k++){ temp[k] = s[0][k+i]; } temp[j-i+1] = 0; makenext(temp); int ok = 1; for(int k=1;k<n;k++){ if(KMP(s[k],temp)==-1){ ok = 0;break; } } //cout<<temp<<" "<<ok<<endl; if(ok&&great(temp,res)){ strcpy(res,temp); } } } if(res[0]){ printf("%s\n",res); }else{ printf("IDENTITY LOST\n"); } } return 0;}
- [KMP或者暴力]POJ 3450 Corporate Identity
- POJ 3450 Corporate Identity 暴力枚举+KMP
- POJ 3450Corporate Identity(暴力枚举+KMP)
- poj 3450 Corporate Identity 【暴力KMP】
- 【poj 3450 Corporate Identity 】 KMP(暴力)
- poj 3450 Corporate Identity(二分长度 + 暴力kmp)
- POJ 题目3450 Corporate Identity(KMP 暴力)
- POJ-3450-Corporate Identity(KMP)
- Corporate Identity (KMP+暴力枚举)
- POJ 3450 Corporate Identity KMP题解
- poj 3450 Corporate Identity(数据结构:KMP)
- POJ 3450--Corporate Identity【KMP && 枚举】
- HDU 2328 Corporate Identity (暴力 | kmp)
- poj 3450 Corporate Identity
- POJ-3450-Corporate Identity
- POJ 3450 Corporate Identity
- POJ 3450 Corporate Identity
- poj 3450 Corporate Identity
- 字符串系列之最长回文子串
- PHP查询MySQL大量数据的内存
- Linux Shell编程基础
- struts2中的验证框架
- eclipse中pydev插件的最新更新网址
- [KMP或者暴力]POJ 3450 Corporate Identity
- POI 与 JXL 的一点比较——关于使用Java操作excel文件
- 优化PHP程序的方法
- 振作只需一个理由:日子不能这样过
- 利用SQL注入漏洞登录后台
- 自定义checkbox样式
- PHP程序员最常犯的11个MySQL错误
- 让PHP COOKIE及时生效,不用刷新就可以使用
- PHP防CC攻击