HDU 3336 Count the string 所有前缀在串中的出现总次数
来源:互联网 发布:极路由网络唤醒 编辑:程序博客网 时间:2024/06/07 12:55
题目链接
题意
给定一个串
思路
考虑
记
由
而在
故有
即
另外,其本身
最后,是否有遗漏呢?
假设漏算了一些串,它们对应前缀的结束位置在
故
最后求个
Code
#include <bits/stdc++.h>#define maxn 200010using namespace std;const int mod = 10007;typedef long long LL;char s[maxn];int f[maxn], n, dp[maxn];void getfail() { f[0] = f[1] = 0; for (int i = 1; i < n; ++i) { int j = f[i]; while (j && s[i] != s[j]) j = f[j]; f[i+1] = s[i] == s[j] ? j+1 : 0; }}void work() { scanf("%d%s", &n, s); getfail(); int ans = 0; for (int i = 1; i <= n; ++i) { (dp[i] = dp[f[i]] + 1) %= mod; (ans += dp[i]) %= mod; } printf("%d\n", ans);}int main() { int T; scanf("%d", &T); while (T--) work(); return 0;}
阅读全文
0 0
- HDU 3336 Count the string 所有前缀在串中的出现总次数
- 所有前缀在串中出现的次数之和 kmp hdu 3336 count the string
- hdoj 3336 Count the string 【kmp求 所有前缀 在原串中出现的次数 总和】
- Hdu 3336 Count the string (KMP+DP 前缀出现次数和)
- hdu 3336Count the string(KMP变形,求前缀出现的次数和)
- hdu 4552 求所有字符串前缀在字符串中出现的总次数
- HDU 3336 KMP 求所有前缀在母串中出现的次数
- HDU 3336 Count the string(KMP:串前缀匹配自身+DP)
- Hdu 3336 Count the string(求给定字符串含前缀的数量)
- HDU 3336 Count the string(KMP+求给定字符串含前缀的数量)
- HDU 3336 Count the string
- hdu 3336 Count the string
- hdu 3336 Count the string
- hdu 3336 Count the string
- hdu 3336 Count the string
- hdu 3336 Count the string
- hdu 3336 Count the string
- HDU-Count the string -3336
- Kotlin从入门到放弃之基础篇(二)——包和控制流
- 2017-09-19HTML基本标签
- 其他-poi的使用(操作excel表格)
- Struts2配置文件
- mysql死锁,可视化工具无法操作
- HDU 3336 Count the string 所有前缀在串中的出现总次数
- TCP的三次握手和四次挥手的过程?三次握手改成两次或者四次可以吗为什么?
- JavaWEB中request.getRequestURI()、getRequestURL()、getContextPath()、getServletPath()区别
- stm32在rt-thread上使用uart4实现gps的输出
- java设计模式综合项目实战
- MySQL事务隔离级别
- WebViewJavascriptBridge
- Linux 删除目录及其子目录指定类型文件
- Spring MVC_10.1:Dispatcher