Codeforces 204 E

题意:给\(n\)个串,求对于每一个串在至少\(k\)个串中出现的它的子串\(S_{l..r}\)有多少个。

思路:后缀自动机上\(dp\)。。。

我们首先构造出这\(n\)个串的后缀自动机,其中需要注意将某个串的构建完了后直接将\(lst\)指针赋为\(root\),那么就可以包含这些串的所有子串并且不会有问题。

然后我们就考虑如何来算出某一个子串在\(n\)个串中出现了多少次。

假设现在我们从\(S_i\)的开头走到第\(j\)位,走到了节点\(u\),那么

看从\(u\)开始,沿着\(link\)一直走到\(root\)的一堆节点\(v_1..v_k\),这些节点表示的最长后缀没有在\(S_i\)中出现过,那么它们现在就标记为在\(S_i\)中出现过了,然后这些节点代表了结尾为\(j\)的所有子串们(根据定义),所以没有漏掉任何一个子串。

下面就是要求每一个节点对\(S_i\)的贡献了。对于节点\(u\),它对任何一个串的贡献就是它的\(link\)的贡献加上如果它出现大于等于\(k\)次,那么就再加上这个节点表示的子串数量:\(len_u-len_{link_u}\)(这个非常重要)。

那么顺着\(S_i\)跑到的每个节点\(u\)统计下答案就可以辣

【Codeforces 204E】Little Elephant and Strings的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 798B】Mike and strings

    [题目链接]:http://codeforces.com/contest/798/problem/B [题意] 给你n个字符串; 每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去 ...

  4. 【52.49%】【codeforces 556A】Case of the Zeros and Ones

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【19.46%】【codeforces 551B】ZgukistringZ

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【codeforces 755B】PolandBall and Game

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【codeforces 750E】New Year and Old Subsequence

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 761C】Dasha and Password(动态规划做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 761C】Dasha and Password(贪心+枚举做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. python爬虫入门---第一篇:获取某一网页所有超链接

    这是一个通过使用requests和BeautifulSoup库,简单爬取网站的所有超链接的小爬虫.有任何问题欢迎留言讨论. import requests from bs4 import Beauti ...

  2. instanceof和typeof的细节

    我骑着小毛驴,喝着大红牛哇,哩个啷格里格朗,别问我为什么这木开心,如果活着不是为了浪荡那将毫无意义 今天来捋一捋我们平日经常用的instanceof和typeof的一些小问题 typeof: type ...

  3. H5新标签(适合新手入门)

    H5新标签 文档类型设定 document HTML: sublime 输入 html:4s XHTML: sublime 输入 html:xt HTML5 sublime 输入 html:5 < ...

  4. mooc《数据结构》 习题1.8 二分查找

    本题要求实现二分查找算法. 函数接口定义: Position BinarySearch( List L, ElementType X ); 其中List结构定义如下: typedef int Posi ...

  5. Android Studio 点击两次返回键,退出APP

    该功能的实现没有特别复杂,主要在onKeyDown()事件中实现,直接上代码,如下: //第一次点击事件发生的时间 private long mExitTime; /** * 点击两次返回退出app ...

  6. 安卓开发之自定义一个view弹出框

    https://www.cnblogs.com/muyuge/p/6152167.html

  7. Scala之List,Set及Map基本操作

    package big.data.analyse.dataSet import scala.collection.immutable.{TreeMap, TreeSet} import scala.c ...

  8. gitlab hooks配置

    1.邮件格式过滤 pre-recieive rev_type=commit # Only check the first commit information due to a lot of comm ...

  9. python 报错RuntimeError: dictionary changed size during iteration

    a = {':0} for b in list(a.keys()): if a[b] == 0: del a[b] print(a) 报错是因为在字典迭代期间改变字典大小 我们可以通过取出字典的键值, ...

  10. Django学习---py3下的富文本编辑器的使用

    背景说明: Ueditor HTML编辑器是百度开源的HTML编辑器,但是在Python3下调用报错,找不到widgets模块,经查发现,DjangoUeditor是基于Python 2.7的,对Py ...