hdu3336-Count the string
2013-04-30 20:51
218 查看
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 ; } else k = 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
- Count the string(hdu3336)
- HDU3336 Count the string (KMP)
- Count the string[HDU3336]
- HDU3336:Count the string
- hdu3336 Count the string(next数组)
- hdu3336 Count the string(kmp+dp)
- hdu3336 Count the string
- 【KMP】 hdu3336 Count the string
- HDU3336-Count the string(KMP)
- hdu3336 Count the string
- [KMP][HDU3336][Count the string]
- HDU3336 Count the string(KMP+DP)
- [KMP][HDU3336][Count the string]
- HDU3336 Count the string(KMP)
- hdu3336 Count the string
- hdu3336 Count the string(dp)
- Count the string---hdu3336(kmp Next数组的运用)
- HDU3336 Count the string