我要吃串串香

字符串诡异测试

顺利爆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[i1]+dp[j]+l d p [ i ] = d p [ i − 1 ] + d p [ j ] + l
AC: dp[i]=dp[i1]+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自动鸡你叫我写字符串??!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值