hdu3336-Count the string
来源:互联网 发布:preview.exe软件下载 编辑:程序博客网 时间:2024/06/05 21:57
Count the string
使用get_next函数多了,渐渐对get_next函数的理解又深了一点点,
这其中dp[i]从1加到n
dp[i]=dp[next[i]]+1;
// File Name: hdu3336.cpp// Author: bo_jwolf// Created Time: 2013年04月30日 星期二 20:39:15#include<vector>#include<list>#include<map>#include<set>#include<deque>#include<stack>#include<bitset>#include<algorithm>#include<functional>#include<numeric>#include<utility>#include<sstream>#include<iostream>#include<iomanip>#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<ctime>using namespace std;const int maxn = 200005 ;int dp[ maxn ] ;const int MOD = 10007 ;char str[ maxn ] ;int next[ maxn ];int len ;void get_next(){int j = 0 , k = -1 ;next[ 0 ] = -1 ;len = strlen( str ) ;while( j < len ){if( k == -1 || str[ j ] == str[ k ] ){j++ ;k++ ;next[ j ] = k ; }elsek = next[ k ] ;}}int main(){int n ;int Case ;int ans ;scanf( "%d" ,&Case );while( Case-- ){scanf( "%d" , &n ) ;scanf( "%s" , str );get_next();dp[ 0 ] = 0 ;ans = 0 ;for(int i = 1 ; i <= n ; i++ ){dp[ i ] = dp[ next[ i ] ] + 1 ;dp[ i ] = dp[ i ] % MOD ;ans += dp[ i ];ans = ans % MOD ;}printf( "%d\n" , ans ) ;}return 0;}
- hdu3336 Count the string
- hdu3336 Count the string
- HDU3336:Count the string
- hdu3336-Count the string
- hdu3336 Count the string
- hdu3336 Count the string
- hdu3336----Count the string
- hdu3336 Count the string
- 【HDU3336】【Count the string】
- HDU3336 Count the string
- HDU3336-Count the string
- 【KMP】 hdu3336 Count the string
- hdu3336 Count the string-------KMP
- hdu3336 Count the string KMP
- [KMP][HDU3336][Count the string]
- HDU3336 Count the string (KMP)
- HDU3336-Count the string(KMP)
- hdu3336 Count the string KMP+dp
- 数学专项number_theory:UVa 10539
- LA 3942 - Remember the Word
- 问题一百二十三:统计子串
- 关于派生类成员变量的内存问题
- 数学专项number_theory:UVa 11105
- hdu3336-Count the string
- n进制小数 将任意十进制正小数分别转换成2,3,4,5,6,7,8,9进制正小数,小数点后保留8位,并输出。
- HDU 3342
- ROS探索总结(四)——简单的机器人仿真
- KMP算法
- Quartz学习(二)--Quartz 框架核心接口
- uva188 - Perfect Hash(完美哈希)
- hdu1272 小希的迷宫
- Householder relections