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 ...
随机推荐
- mysql 远程访问 配置
sudo vi /etc/mysql/my.cnf 找到bind-address = 127.0.0.1 注释掉这行:#bind-address = 127.0.0.1 或者改为: bind-addr ...
- 在xcode6.1和ios10.10.1环境下实现app发布
之前写过在xcode6.1和ios10.10.1环境下实现真机测试,以及最近提交的app一直在审核当中,所以木有发布如何实现app发布来分享给大家.刚好昨天app审核通过了,所以就分享一篇如何实现ap ...
- Jdbc工具类(连接及释放)
package cn.gdpe.jdbc; import java.io.File;import java.io.FileInputStream;import java.io.FileNotFound ...
- [转] 使用CSS3 will-change提高页面滚动、动画等渲染性能 ---张鑫旭
一.先来看一个例子 下面这个例子来自某外文,我这里简单转述下. 视差滚动现在不是挺流行的嘛,然后Chris Ruppel当其使用background-attachment: fixed实现背景图片不随 ...
- ng的数据绑定
ng创建了一个自己的事件循环,当浏览器事件(常用的dom事件,xhr事件等)发生时,对DOM对应的数据进行检查,若更改了,则标记为脏值,并进入更新循环,修改对应的(可能是多个) DOM的参数.这样就实 ...
- php定时删除文件夹下文件(清理缓存文件)
<?php ignore_user_abort(); //客户端断开时,可以让脚本继续在后台执行 set_time_limit(0); //忽略php.ini设置的脚本运行时间限制 $inter ...
- 多选select实现左右添加删除
案例:实现效果 1.选择监控城市,车辆列表显示对应城市所有车辆 2.从左边选择车辆 单击 >> 实现右侧显示添加车辆 ,左侧对应移除已选择车辆 3.右侧选中车辆 单击 &l ...
- 架设wordpress再vps上的 一些感想总结
日本vps.樱花系列 配置: 2cpu+1G内存+100G硬盘 系统 第一次我把默认的centos 给换了..原因就是,不会linux.而且我主要用.net 感觉 mono也行.但是linux不会. ...
- SHELL要发送HTML这类邮件的话,还得靠msmtp 和 mutt
参考蛮多的.. http://storysky.blog.51cto.com/628458/293005 http://www.wilf.cn/post/centos-mutt-msmtp-setup ...
- [原创]leet code - path sum
; ; ; } } ; }};