【HDOJ】1238 Substrings

深搜+剪枝,简单字符串。

 #include <stdio.h>
#include <string.h> #define MAXLEN 105
#define MAXNUM 105 char buf[MAXNUM][MAXLEN];
char src1[MAXLEN], src2[MAXLEN];
int case_n, n; int f(int index, int len) {
int max = ;
int i=, j, k;
char *p; while (i+max < len) {
for (j=; j<=max; ++j)
src1[j] = src2[max-j] = buf[index][i+j];
src1[max+] = src2[max+] = '\0';
k = ;
for (j=; j<n; ++j) {
p = strstr(buf[j], src1);
if (p == NULL)
p = strstr(buf[j], src2);
if (p == NULL) {
k = ;
break;
}
}
if (k)
++max;
else
++i;
} return max;
} int main() {
int i, j, tmp, len; scanf("%d", &case_n); while (case_n--) {
scanf("%d", &n);
tmp = MAXLEN;
for (i=; i<n; ++i) {
scanf("%*c%s", buf[i]);
len = strlen(buf[i]);
if (len < tmp) {
tmp = len;
j = i;
}
}
tmp = f(j, tmp);
printf("%d\n", tmp);
} return ;
}
上一篇:SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)【转】


下一篇:移动端touch实现下拉刷新