bzoj1009: [HNOI2008]GT考试 矩阵乘法
来源:互联网 发布:网络校时器 编辑:程序博客网 时间:2024/05/22 15:16
#include <iostream>#include <cstring>#include <algorithm>#include <cmath>#include <cstdio>using namespace std;int mod,n,m;char str[1000];int next[1000];void kmp(){ int j=0; next[1]=0; for(int i=2;i<=m;i++) { while(j&&str[j+1]!=str[i]) { j=next[j]; } if(str[j+1]==str[i]) j++; next[i]=j; }}struct matrix{ int a[30][30];}f,res;matrix operator *(matrix x,matrix y){ matrix z;memset(z.a,0,sizeof(z.a)); for(int i=0;i<m;i++) { for(int j=0;j<m;j++) { for(int k=0;k<m;k++) { z.a[i][j]+=(x.a[i][k]*y.a[k][j])%mod; z.a[i][j]%=mod; } } } return z;}void qpow(){ memset(res.a,0,sizeof(res.a)); for(int i=0;i<m;i++) res.a[i][i]=1; while(n) { if(n&1) res=res*f; n=n>>1; f=f*f; }}int main(){ memset(f.a,0,sizeof(f.a)); scanf("%d%d%d",&n,&m,&mod); scanf("%s",str+1); kmp(); for(int i=0;i<m;i++) { for(int j=0;j<=9;j++) { int t=i; while(t&&str[t+1]-'0'!=j) t=next[t]; if(str[t+1]-'0' == j) t++; f.a[i][t] = (f.a[i][t]+1)%mod; } } qpow(); int fans = 0; for(int i = 0; i < m; i++) fans = (fans+res.a[0][i])%mod; printf("%d\n",fans); return 0;}
0 0
- bzoj1009: [HNOI2008]GT考试 矩阵乘法
- [矩阵乘法+KMP] BZOJ1009: [HNOI2008]GT考试
- BZOJ1009 [HNOI2008]GT考试 矩阵
- 【BZOJ1009】【HNOI2008】GT考试 AC自动机+矩阵乘法
- [BZOJ1009]HNOI2008 GT考试|KMP|递推|矩阵乘法
- 【DP+KMP+矩阵乘法】BZOJ1009(HNOI2008)[GT考试]题解
- 【KMP+矩阵加速】BZOJ1009[HNOI2008]GT考试
- 【bzoj1009】[HNOI2008]GT考试 矩阵+kmp+DP
- bzoj1009: [HNOI2008]GT考试
- [bzoj1009][HNOI2008]GT考试
- BZOJ1009 HNOI2008 GT考试
- 【bzoj1009】[HNOI2008]GT考试
- [BZOJ1009][HNOI2008]GT考试
- [HNOI2008] [BZOJ1009] GT考试
- 【BZOJ1009】【HNOI2008】GT考试
- BZOJ1009: [HNOI2008]GT考试
- bzoj1009【HNOI2008】GT考试
- BZOJ1009 [HNOI2008]GT考试
- linearLayout下设置selector不起作用的解决方法
- Android 内存管理
- Microsoft Mole原理及常见问题整理
- 医疗时鲜资讯:浅谈专科细分领域“口腔、眼科”的发展
- leetcode:Remove Duplicates from Sorted Array II 菜鸟解法
- bzoj1009: [HNOI2008]GT考试 矩阵乘法
- ubuntu 12.04 安装eclipse 折腾了快一天了。
- 中国大陆可以打开的国外新闻网站 了解世界的窗口 学习英语的好机会
- 更新xcode 目录发生变化
- Servlet
- 计算几何-点与多边形的位置
- Debian 64位安装wink
- 计算几何-凸包问题
- unbuntu node.js 最快安装