zoukankan      html  css  js  c++  java
  • uoj5

    1、30分做法

         枚举子串,对于每个子串枚举前缀,并与后缀判断比较,时间复杂度(L3),空间复杂度(L)

    const oo=1000000007;maxn=1000000+10;
    var t,i1,len,i,j:longint;
        num:array[0..maxn] of int64;
        ans:int64;
        s,s1,s2:ansistring;
    begin
    readln(t);
    for i1:=1 to t do
    begin
      readln(s);
      len:=length(s);
      ans:=1;
      for i:=1 to len do
      begin
        num[i]:=0;
        for j:=1 to i div 2 do
        begin
          s1:=copy(s,1,j);
          s2:=copy(s,i-j+1,j);
          if s1=s2 then inc(num[i]);
        end;
        ans:=ans*(num[i]+1) mod oo;
      end;
      writeln(ans);
    end;
    end.
    

    2、100分做法

         一眼看去像KMP 然而KMP学一次忘一次

         woc我也不知道该怎么讲贴个标程算了

         时间复杂度(L),空间复杂度(L)

    const oo=1000000007;maxn=1000000+10;
    var t,i1,len,i,j:longint;
        num,next:array[0..maxn] of int64;
        ans:int64;
        s:ansistring;
    begin
    readln(t);
    for i1:=1 to t do
    begin
      readln(s);
      len:=length(s);
      j:=0;num[1]:=1;
      for i:=2 to len do
      begin
        while (j>0)and(s[j+1]<>s[i]) do j:=next[j];
        if s[j+1]=s[i] then inc(j);
        next[i]:=j;
        num[i]:=num[j]+1;
      end;
      j:=0;ans:=1;
      for i:=2 to len do
      begin
        while (j>0)and(s[j+1]<>s[i]) do j:=next[j];
        if s[j+1]=s[i] then inc(j);
        while 2*j>i do j:=next[j];
        ans:=ans*(num[j]+1) mod oo;
      end;
      writeln(ans);
    end;
    end.
    

      

  • 相关阅读:
    RabbitMq安装笔记
    SpringBoot笔记--Jackson
    SpringBoot笔记--FastJson
    由一个“两次请求”引出的Web服务器跨域请求访问问题的解决方案
    转:SpringMVC之类型转换Converter(GenericConverter)
    npm 命令
    数据分页技巧
    Mongo 开发笔记
    Android 开发
    Bash 笔记
  • 原文地址:https://www.cnblogs.com/x1273011572/p/6708615.html
Copyright © 2011-2022 走看看