题解:利用next数组来保存前缀位置,递推求解。

#include <cstdio>
#include <cstring>
char pat[200005];
int next[200005],M,f[200005];
const int MOD=10007;
int getnext(){
int i=1,j=0;next[1]=0;
while(i<M){
if(j==0||pat[j]==pat[i])next[++i]=++j;
else j=next[j];
}
}
int main(){
int T,i; scanf("%d",&T);
while(T--){
scanf("%d",&M);
scanf("%s",pat+1);
pat[0]='#'; M=strlen(pat);
pat[M]='*'; getnext(); f[1]=0;
int s=0; for(i=2;i<=M;i++)(s+=(f[i]=f[next[i]]+1))%=MOD;
printf("%d\n",s);
}
return 0;
}

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+DP优化

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

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

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

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

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

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

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

  6. 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 ...

  7. HDU 3336 Count the string KMP

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

  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 ...

  10. hdu 3336 Count the string(思维可水过,KMP)

    题目 以下不是KMP算法—— 以下是kiki告诉我的方法,好厉害的思维—— 就是巧用标记,先标记第一个出现的所有位置,然后一遍遍从标记的位置往下找. #include<stdio.h> # ...

随机推荐

  1. 001.web前端-学习了解

    学习web前端开发基础技术需要掌握:HTML.CSS.JavaScript语言.下面我们就来了解下这三门技术都是用来实现什么的: 1.html(Hypertext Markup Language)—— ...

  2. spoj ONP - Transform the Expression 中缀转后缀

    题目链接 将中缀表达式转化为后缀表达式. 数字的话直接放到答案的字符串里. 如果是左括号就进栈, 右括号就让栈里的符号都出来直到第一个左括号. 否则的话比较当前符号的优先级和栈顶符号的优先级. #in ...

  3. python初学笔记(三)

    Unicode字符串 字符串还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字节 (byte),所以,一 ...

  4. poj1617---columnar encryption

    题意:给出keyword,如BATBOY,A的ascii值最小,所以第二列最先输出,B有两个,左边的先输出,也就是说,接下来输出第一列和第4列, 所以每一个字母都带有一个ascii值和一个序号,用结构 ...

  5. struts2 全局格式化,格式化时间,金钱,数字

    //在前台页面去控制时间,数字,小数,金钱,是极其不明智的选择,除非你是写了良好的 js api 像freemarker , struts 都有良好的标签,我们应该好好利用,才发现的,给大家分享一下 ...

  6. Android的MVC框架

    http://www.cnblogs.com/wanghafan/archive/2012/07/20/2600786.html MVC是当前比较流行的框架,随便Google下,就可以发现几乎所有的应 ...

  7. HTML之学习笔记(三)文本标签

    标题标签 html的标题标签从h1~h6共六个级别,权值不断降低,即不断变小,不用使用CSS控制来取代h标签,因为网页搜索引擎通过搜索到你的页面,找到你页面的h标签并为h标签建立索引,如果h标签被替代 ...

  8. Asp.Net Memcached安装配置使用、安全性

    Memcached安装配置使用  一,准备        你需要有一下软件:       VS.NET(05/08)       SQLSERVER       memcached服务器端以及客户端类 ...

  9. 将单链表的每K个节点之间逆序

    [说明]: 本文是左程云老师所著的<程序员面试代码指南>第二章中“将单链表的每K个节点之间逆序”这一题目的C++复现. 本文只包含问题描述.C++代码的实现以及简单的思路,不包含解析说明, ...

  10. JS图标插件

    1.web开发中,有时候需要图标等控件,amcharts可以胜任. amcharts官方网址:http://www.amcharts.com/javascript-charts/