Count the string - HDU 3336(next+dp)
#include<stdio.h>
#include<string.h> const int MAXN = 1e6+;
const int oo = 1e9+;
const int mod = ; char s[MAXN];
int next[MAXN], dp[MAXN]; void GetNext(char s[], int N)
{
int i=, j=-;
next[] = -; while(i < N)
{
if(j==- || s[i]==s[j])
next[++i] = ++j;
else
j = next[j];
}
} int main()
{
int T, N, ans; scanf("%d", &T); while(T--)
{
scanf("%d%s", &N, s); GetNext(s, N); next[N+] = -;
ans = dp[] = ; for(int i=; i<=N; i++)
{
dp[i] = (dp[next[i]] + ) % mod;
ans = (ans+dp[i]) % mod;
} printf("%d\n", ans);
} return ;
}
Count the string - HDU 3336(next+dp)的更多相关文章
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- (KMP)Count the string -- hdu -- 3336
http://acm.hdu.edu.cn/showproblem.php?pid=3336 Count the string Time Limit: 2000/1000 MS (Java/Other ...
- You Are the One HDU - 4283 (区间DP)
Problem Description The TV shows such as You Are the One has been very popular. In order to meet the ...
- LOOPS HDU - 3853 (概率dp):(希望通过该文章梳理自己的式子推导)
题意:就是让你从(1,1)走到(r, c)而且每走一格要花2的能量,有三种走法:1,停住.2,向下走一格.3,向右走一格.问在一个网格中所花的期望值. 首先:先把推导动态规划的基本步骤给出来. · 1 ...
- HDU - 2196(树形DP)
题目: A school bought the first computer some time ago(so this computer's id is 1). During the recent ...
- Count the string HDU - 3336
题意: 求一个字符串的每个前缀在这个字符串中出现次数的加和 解析: 默默的骂一句...傻xkmp..博主心里气愤... 拓展kmp就好多了... 因为拓展kmp每匹配一次 就相当于这些前缀出现了一 ...
- HDU 6148 (数位DP)
### HDU 6148 题目链接 ### 题目大意: 众所周知,度度熊非常喜欢数字. 它最近发明了一种新的数字:Valley Number,像山谷一样的数字. 当一个数字,从左到右依次看过去数字没有 ...
- HDU5898、 HDU 2089(数位DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5898 题意:很明确,找出区间[l , r]中符合连续奇数为偶数,连续偶数为奇数的个数. 思路:dp[i ...
- HDU 4035Maze(概率DP)
HDU 4035 Maze 体会到了状态转移,化简方程的重要性 题解转自http://blog.csdn.net/morgan_xww/article/details/6776947 /** dp ...
随机推荐
- 用于显示上个月和下个月_PHP
/** * 用于显示上个月和下个月 * @param int $sign 1:表示上个月 0:表示下个月 * @return string */ function GetMonth($sign=&qu ...
- Maven搭建Spring+Struts2+Hibernate项目详解
http://www.bubuko.com/infodetail-648898.html
- JavaScript Window - 浏览器对象模型
浏览器对象模型 (BOM) 使 JavaScript 有能力与浏览器"对话". 浏览器对象模型 (BOM) 浏览器对象模型(Browser Object Model (BOM))尚 ...
- 【POJ2482】【线段树】Stars in Your Window
Description Fleeting time does not blur my memory of you. Can it really be 4 years since I first saw ...
- Struts2中的链接标签 <s:url>和<s:a>---在action中获取jsp表单提交的参数(转)
转自:http://sgl124764903.iteye.com/blog/444183 1.普通链接 Web程序中最普通的应用是链接到其他页面,下面看Welcome.jsp. <%@ page ...
- assert sys.modules[modname] is old_mod
使用了pypiwin32 包中的pythoncom的时候,当跑在apache下,日志报错: [Thu Aug 27 17:06:44 2015] [error] [client 127.0.0.1] ...
- glide简介
golang包管理工具glide简介 golang包管理工具glide简介 前言 golang是一个十分有趣,简洁而有力的开发语言,用来开发并发/并行程序是一件很愉快的事情.在这里我感受到了其中一 ...
- iOS触摸事件处理
iOS触摸事件处理 主要是记录下iOS的界面触摸事件处理机制,然后用一个实例来说明下应用场景. 一.处理机制 界面响应消息机制分两块, (1)首先在视图的层次结构里找到能响应消息的那个视图. (2 ...
- hadoop 异常 datanode未启动
暴力方法:(本人是学习阶段,实际工作中不能这么做)在各个节点上执行如下操作. 将/tmp 删除 将 conf/mapred-site.xml <property> <name> ...
- 【转】nodejs
Node.JS + MongoDB技术讲座 云计算 + 大数据 = 未来. 在中国的云计算上基本上是一个概念,个人感觉与当初的SOA没有太大的区别,空泛的理论. 中小型开发的未来 ...