【Codeforces 204E】Little Elephant and Strings
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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 798B】Mike and strings
[题目链接]:http://codeforces.com/contest/798/problem/B [题意] 给你n个字符串; 每次操作,你可以把字符串的每个元素整体左移(最左边那个字符跑到最后面去 ...
- 【52.49%】【codeforces 556A】Case of the Zeros and Ones
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【19.46%】【codeforces 551B】ZgukistringZ
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 755B】PolandBall and Game
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750E】New Year and Old Subsequence
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761C】Dasha and Password(动态规划做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761C】Dasha and Password(贪心+枚举做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- CDN使用心得:加速双刃剑
文章图片存储在GitHub,网速不佳的朋友,请看<CDN 使用心得:加速双刃剑> 或者 来我的技术小站 godbmw.com 本文以腾讯云平台的 CDN 服务为例,记录下在个人网站开发和公 ...
- MinGW编译Mongo-CXX-Driver
8. mongo-cxx-driver pacman -S mingw-w64-x86_64-cyrus-sasl pacman -S mingw-w64-x86_64-extra-cmake-mod ...
- Java数据解析---PULL
安卓和JAVA解析xml文件的三种方式: 1.PULL解析 2.SAX解析 3.DOM解析 三者各有所长,依情况选择解析方式 1.PULL和SAX均采用流式解析,意味着只能从头读到底,无法像DOM解析 ...
- (网页)20个JS 小技巧超级实用
转自CSDN: 1. 将彻底屏蔽鼠标右键 oncontextmenu=”window.event.returnValue=false”< table border oncontextmenu=r ...
- (后端)如何将数据库的表导出生成Excel?
1.如何通过元数据拿到数据库的信息? 2.如何用Java生成Excel表? 3.将数据库中的表导出生成Excel案例 如何通过元数据拿到数据库的信息 元数据:描述数据的数据 Java中使用元数据的两个 ...
- Python参数传递(传值&传引用)
# 测试参数是传值还是传引用def test(arg): print("test before") print(id(arg)) arg[1]=30 # 测试可变对象 # arg[ ...
- Dell XPS 13 9306安装 macOS 10.12.6
一直在考虑买一个手上的本,轻薄,办公方便.个人很喜欢mac 下的那些软件,尤其是keynote.就锁定在Macbook Pro上,但是又觉得没有什么玩头,后来一直找,觉得xps也很符合要求,就开始调查 ...
- 手动将经典 VM 从 VHD 迁移到新的 ARM 托管磁盘 VM
本部分有助于将现有 Azure VM 从经典部署模型迁移到资源管理器部署模型中的托管磁盘. 计划迁移到托管磁盘 本部分可帮助你针对 VM 和磁盘类型做出最佳决策. 位置 选取 Azure 托管磁盘可用 ...
- python第一百零二天-----第十七周作业
由于内容众多 直接使用 git 链接 : https://github.com/uge3/hosts_masg 主机管理WEB页面 使用 SQLALchemy 主机管理(8列) ip 用户表: 用户名 ...
- 描述性统计的matlab实现
理论讲的再多不会做也白弄 直接上手 一.针对接近正态分布的(均值,方差,标准差,极差,变异系数,偏度,峰度) 这里我必须提前说明一点就是,你在写好函数后,函数的名是dts,你保存的文件名也必须是dts ...