【BZOJ 3670】[Noi2014] 动物园

题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3670
离线版题目:http://paste.ubuntu.com/17902051/

想了很久。最后觉得SAM+链剖+主席树可捉,一看数据范围,这个有问题啊!
于是可耻的看了题解,我再也不敢说KMP简单了,MD小性质有一堆QAQ
干货写在《KMP总结》里,这里只扔一份代码吧!

#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;

const int MAXN = 1000000+9;
const LL MOD = 1000000007;

char pat[MAXN];
int n,fail[MAXN],cnt[MAXN];

int main(){
	int T; cin>>T;
	while (T--){
		scanf("%s",pat+1);
		n = strlen(pat+1); cnt[1] = 1;
		for (int i=2,j=0;i<=n;i++){
			while (j && pat[j+1] != pat[i]) j = fail[j];
			if (pat[j+1] == pat[i]) j++;
			fail[i] = j; cnt[i] = cnt[fail[i]] + 1;
		} LL vout = 1;
		for (int i=2,j=0;i<=n;i++){ while (j && pat[j+1] != pat[i]) j = fail[j]; if (pat[j+1] == pat[i]) j++; while (j && j*2 > i) j = fail[j];
			vout = (vout*(cnt[j]+1)) % MOD;
		}
		printf("%d\n",int(vout));
	}
	return 0;
} 

14 thoughts to “【BZOJ 3670】[Noi2014] 动物园”

  1. I’m really enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Great work!

  2. 912297 844887I think other site proprietors ought to take this site as an model, very clean and superb user genial style . 758473

  3. 787765 950406I used to be far more than happy to seek out this internet-site.. I dont even know how I ended up here, but I thought this post was wonderful. A lot more A rise in Agreeable. 859539

  4. 219256 179522Hmm is anyone else experiencing troubles with the images on this blog loading? Im trying to locate out if its a problem on my finish or if its the blog. Any feed-back would be greatly appreciated. 953149

  5. 341652 946137You made some respectable points there. I looked on the internet for the concern and identified a lot of people will go along with together with your internet site. 393387

  6. 356004 482634Hi there, just became aware of your weblog via Google, and located that its truly informative. Ill be grateful in the event you continue this in future. Lots of individuals will benefit from your writing. Cheers! 625776

Leave a Reply to qiuqiu99 Cancel reply

Your email address will not be published. Required fields are marked *