标签:
#include<cstdio>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int oo = 1e9+7;
const int maxn = 1e6+7;
char str[510][2010];
int n, ans;
void dfs(int x)
{
int i;
if(x <= 1 || ans == n) return ;
if(strstr(str[x], str[x-1])!=NULL)
dfs(x-1);
else
{
for(i = n; i > x-1; i--)///搜到当前位置
{
if(strstr(str[i], str[x-1]) == NULL)
{
ans = max(i, ans);
}
}
dfs(x-1);///可能还会存在前面的字符串符合条件 继续搜。
}
}
int main()
{
int i, T, cas=1;
scanf("%d", &T);
while(T--)
{
ans = -1;
scanf("%d", &n);
for(i = 1; i <= n; i++)
scanf("%s", str[i]);
dfs(n);
printf("Case #%d: %d\n", cas++, ans);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/PersistFaith/p/4925568.html