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.
    

      

  • 相关阅读:
    聚类算法学习-kmeans,kmedoids,GMM
    hdu
    高仿精仿微信应用ios源码下载
    UVA 116 Unidirectional TSP 经典dp题
    [置顶] 动态规划之切割钢条
    poj
    求解printf函数?
    实现多文件上传在iOS开发中
    开源DirectShow分析器和解码器: LAV Filter
    <Win32_20>纯c语言版的打飞机游戏出炉了^_^
  • 原文地址:https://www.cnblogs.com/x1273011572/p/6708615.html
Copyright © 2011-2022 走看看