【题意概述】

  给定一个文本字符串,找出所有的前缀,并把他们在文本字符串中的出现次数相加,再mod10007,输出和。

【题目分析】

  利用kmp算法的next数组 再加上dp

【存在疑惑】

  在分析next数组和dp之间的关系,结论是 dp[i] = (dp[next[i]]+1); 搞不懂之间存在的联系

【AC】

 #include <bits/stdc++.h>

 int n,m,dp[],next[];

 char s[];

 void getnext() {
int i=,j=-; next[]=-; while(i<m) { if(j==-||s[i]==s[j]) {
++i;++j; next[i]=j; } else
j=next[j];
}
} int main() { scanf("%d",&n); while(n--)
{
int sum=; scanf("%d",&m); scanf("%s",s); getnext(); memset(dp,,sizeof(dp)); for(int i=;i<=m;++i) {
dp[i]=(dp[next[i]]+)%;//不理解
sum=(sum+dp[i])%;
}
printf("%d\n",sum);
}
return ;
}

参考博客:https://www.cnblogs.com/yuelingzhi/archive/2011/08/03/2126346.html

ACM hdu 3336 Count the string的更多相关文章

  1. HDU 3336 Count the string(KMP的Next数组应用+DP)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 3336 Count the string KMP

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3336 如果你是ACMer,那么请点击看下 题意:求每一个的前缀在母串中出现次数的总和. AC代码: # ...

  3. hdu 3336 Count the string KMP+DP优化

    Count the string Problem Description It is well known that AekdyCoin is good at string problems as w ...

  4. HDU 3336 Count the string(next数组运用)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 3336 Count the string 查找匹配字符串

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. hdu 3336:Count the string(数据结构,串,KMP算法)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 3336 Count the string -KMP&dp

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

  8. 【HDU 3336 Count the string】

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  9. HDU 3336——Count the string

    It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...

随机推荐

  1. 前端 jQuery

    一.jQuery是什么? <1>jQuery由美国人John Resig创建,至今已吸引了来自世界各地众多JavaScript高手加入其team. <2>jQuery是继pro ...

  2. Oracle:如何使用PL/SQL 11.0连接远程Oracle12c服务器?

    背景: 如何实现远程连接服务器上的oracle12c? 1.安装一个oracle12c空库,使用oracle12c中集成的oracle pl/sql developer工具实现连接远程服务器上的ora ...

  3. 使用 RHEL(RedHat)6.1 iso 安装包 安装Samba过程

    今天因为工作的需要安装了(RHEL)redhat 6.1 自己为了方便就安装Samba 以记之. 注:Linux系统是刚刚安装好的所以没有samba安装的任何记录. 安装准备: ISO:RHEL_6. ...

  4. 竞赛基础篇---部分和问题(DFS)

    问题链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1058 描述 给定整数a1.a2........an,判断是否可以从中选出若干数,使 ...

  5. from sys import argv

    from sys import argv  初学理解: sys 为内置模块,提供了许多函数和变量来处理 Python 运行时环境的不同部分.是固定的用法,不能自己随便写名字代替它,这行的作用就是要把用 ...

  6. 宝宝巴士-自动化团队-纵世科技-Wiger-原创分享-QQ:18630195

    软件定制请联系QQ: 更新原创技术博客,以及学习心得...... 软件定制请联系QQ:

  7. [LeetCode] Split Array with Equal Sum 分割数组成和相同的子数组

    Given an array with n integers, you need to find if there are triplets (i, j, k) which satisfies fol ...

  8. [UOJ UR#16]破坏发射台

    来自FallDream的博客,未经允许,请勿转载,谢谢. 传送门 先考虑n是奇数的情况,很容易想到一个dp,f[i][0/1]表示转移到第i个数,第i个数是不是第一个数的方案数,然后用矩阵乘法优化一下 ...

  9. [Codeforces]813F Bipartite Checking

    往期题目补档.既然被选为了经典题就拿来写一写. Description 给定一张含有n个点的无向图,一开始图中没有任何边.依次给出q次操作,每次操作给出两个点“x y”,若x和y之间没有边相连,则连上 ...

  10. hdu 5637 BestCoder Round #74 (div.2)

    Transform  Accepts: 7  Submissions: 49  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 131072 ...