字符串诡异测试
顺利爆0;
这次考试太仓促了一点。
AC自动机的模板都还没有写对。
就开始考试了
一开始就抱着一个0000000000000000000的心态去考试,一看,只会强版暴力。
觉得
cout<<0;
c
o
u
t
<<
0
;
分都要多一些。
①对题分析
T1:自己写了一个n*n*k的dp,觉得,样例都跑了1秒。果断
cout<<0
c
o
u
t
<<
0
,觉得这样可能都比暴力分要多些。
于是Wen_kr没有特判零,Justin_Zhao为了不因为卡kr而不造0。
(∗≧▽≦)ツ┏━┓
(
∗
≧
▽
≦
)
ツ
┏
━
┓
听了Wen_kr的优化方法,果断有力的1A了。
题目链接:codeforces176b
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
char a[1000001],b[1000001];
int main()
{
freopen("word.in","r",stdin);
freopen("word.out","w",stdout);
cin>>a>>b;
long long n,ans1=0,ans2=0,cnt=0;
scanf("%lld",&n);
int len=strlen(a);
if (a==b) ans1=1;
else ans2=1;
for(int i=0;i<len;i++)
{
int fl=1;
for(int j=0;j<strlen(b);j++)
{
if (a[(i+j)%len]!=b[j])
{
fl=0;
break;
}
}
if (fl) cnt++;
}
for(int i=0;i<n;i++)
{
int tmp=ans1;
ans1=(cnt*ans2+(cnt-1)*ans1)%mod;
ans2=((len-cnt)*tmp+(len-cnt-1)*ans2)%mod;
}
printf("%lld",ans1);
return 0;
}
啦啦啦啦啦。
T2:
考的时候我把dp方程写错啦。
WA:
dp[i]=dp[i−1]+dp[j]+l
d
p
[
i
]
=
d
p
[
i
−
1
]
+
d
p
[
j
]
+
l
AC:
dp[i]=dp[i−1]+sum(dp[j])+l
d
p
[
i
]
=
d
p
[
i
−
1
]
+
s
u
m
(
d
p
[
j
]
)
+
l
结果样例都过不了。
*fuck
cout<<0;
c
o
u
t
<<
0
;
先写next数组,KMP,存储last,在dp,不难易懂。
②分析成绩
lz现在都是WA自动鸡你叫我写字符串??!