• HDU 3336 Count the string


     1 //this problem is same like to (POJ)Seek the Name, Seek the Fame
     2 #include <iostream>
     3 #include <cstring>
     4 #include <string>
     5 #include <algorithm>
     6 #define N 200010
     7 using namespace std;
     8 
     9 char a[N];
    10 int Next[N];
    11 int Len;
    12 int dp[N];//dp[i] represents from 1 ~ i strings, how many prefixs are end by i
    13 const int mod = 10007;
    14 
    15 void GetNext()
    16 {
    17     int i = 0, j = Next[0] = -1;
    18     while (i < Len)
    19     {
    20         if (j == -1 || a[i] == a[j])
    21             Next[++i] = ++j;
    22         else
    23             j = Next[j];
    24     }
    25 }
    26 
    27 int main(void)
    28 {
    29     ios::sync_with_stdio(false);
    30     int cas;
    31     cin >> cas;
    32     while (cas--)
    33     {
    34         cin >> Len >> a;
    35         GetNext();
    36         int res = 0;
    37         memset(dp, 0, sizeof(dp));
    38         for (int i = 1; i <= Len; ++i)
    39         {
    40             dp[i] = (dp[Next[i]] + 1) % mod;// eg:(1 + 1) % mod <=> 1 % mod + 1 % mod
    41             res = (res + dp[i]) % mod;
    42         }
    43         cout << res << endl;
    44     }
    45 
    46     return 0;
    47 }
  • 相关阅读:
    django 单表操作
    爬虫学习
    DRF源码分析
    DRF权限和频率限制
    DRF版本和认证源码分析
    request高级部分
    多任务异步爬虫及selenium模块使用
    requests基本使用
    爬虫介绍及环境
    Flask生命周期的源码流程
  • 原文地址:https://www.cnblogs.com/ducklu/p/8989223.html
Copyright © 2020-2023  润新知