您的位置:首页 > 其它

HDU 3336 Count the string(乱搞)

2012-08-17 19:01 330 查看
题目链接

有点BFS的思想,不过还是感觉像是乱搞题。。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 200001
#define M 10007
char str
;
int p
;
int main()
{
int i,j,t,n,start,end,ans;
scanf("%d",&t);
while(t--)
{
scanf("%d%*c",&n);
gets(str);
ans = n%M;
start = 0;
j = 0;
for(i = 1;i <= n-1;i ++)
{
if(str[i] == str[0])
{
p[j] = i;
ans++;
j ++;
}
}
end = j-1;
for(i = 1;i <= n-1;i ++)
{
j = 0;
while(start <= end)
{
if(str[p[start]+1] == str[i])
{
ans++;
p[j] = p[start]+1;
j ++;
}
start ++;
}
if(ans > M)
ans = ans%M;
if(j == 0)
break;
start = 0;
end = j-1;
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: