You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
typedef long long LL ;
int n , m , mod ;
const int N = 1e6 + 10 ;
int ne [ N ] ; // kmp的ne数组, 针对模式串s
char s [ N ] ; // 模式串s
int f [ N ] [ 22 ] ; // dp数组
//原始版本, 就是设计密码那道题的代码, 可以过4个点, 剩余6个点TLE
int main ( ) {
cin > > n > > m > > mod ;
cin > > s + 1 ;
// kmp
for ( int i = 2 , j = 0 ; i < = m ; i + + ) {
while ( j & & s [ j + 1 ] ! = s [ i ] ) j = ne [ j ] ;
if ( s [ j + 1 ] = = s [ i ] ) j + + ;
ne [ i ] = j ;
}
//普通dp
f [ 0 ] [ 0 ] = 1 ;
for ( int k = 0 ; k < n ; k + + )
for ( int i = 0 ; i < m ; i + + )
for ( char c = ' 0 ' ; c < = ' 9 ' ; c + + ) {
int j = i ;
while ( j & & s [ j + 1 ] ! = c ) j = ne [ j ] ;
if ( s [ j + 1 ] = = c ) j + + ;
//在kmp过程中进行判断,不能命中m个长度, 需要避让
if ( j < m ) f [ k + 1 ] [ j ] = ( f [ k + 1 ] [ j ] + f [ k ] [ i ] ) % mod ;
}
int res = 0 ;
for ( int i = 0 ; i < m ; i + + ) res = ( res + f [ n ] [ i ] ) % mod ;
printf ( " %d \n " , res ) ;
return 0 ;
}