• [HAOI2015] 数字串拆分


    题目链接

    矩阵加速裸题。注意G(x+1)=G(x)*A。

    // luogu-judger-enable-o2
    #include <bits/stdc++.h>
    #define ll long long 
    using namespace std;
    
    const int N=5e2+5;
    const int inf=0x3f3f3f3f;
    const int mod=998244353;
    
    int n,m;
    char str[N];
    
    struct Node {
    	int a[6][6];
    	inline int*operator[](const int&d) {return a[d];}
    	inline const int*operator[](const int&d) const{return a[d];}
    	inline Node operator*(const Node&b) const{
    		Node c; 
    		memset(&c,0,sizeof c);
    		for(int i=1; i<=m; ++i) 
    		for(int k=1; k<=m; ++k) if(a[i][k]) 
    		for(int j=1; j<=m; ++j) (c[i][j]+=1LL*a[i][k]*b[k][j]%mod)%=mod;
    		return c;
    	}
    	inline Node operator+(const Node&b) const{
    		Node c; 
    		memset(&c,0,sizeof c);
    		for(int i=1; i<=m; ++i) 
    		for(int j=1; j<=m; ++j) c[i][j]=(a[i][j]+b[i][j])%mod;
    		return c;
    	}
    };
    Node f[N],g[N][N],pw[N];
    
    inline Node pow10(Node x) {
    	Node t=x=x*x; x=x*x;
    	return x*x*t;
    }
    
    int main() {
    	scanf("%s%d",str+1,&m);
    	n=strlen(str+1);
    	for(int i=1; i<=m; ++i) pw[0][i][i]=1;
    	for(int i=1; i<=m; ++i) pw[1][i][m]=1;
    	for(int i=2; i<=m; ++i) pw[1][i][i-1]=1;
    	for(int i=2; i<10; ++i) pw[i]=pw[1]*pw[i-1];
    	for(int i=1; i<=n; ++i) {
    		g[i][i-1]=pw[0];
    		for(int j=i; j<=n; ++j) {
    			g[i][j]=pow10(g[i][j-1])*pw[str[j]-'0'];
    		}
    	}
    	f[0]=pw[0];
    	for(int i=1; i<=n; ++i) 
    	for(int j=i-1; ~j; --j) f[i]=f[i]+f[j]*g[j+1][i];
    	int ans=0;
    	for(int i=1; i<=m; ++i) (ans+=f[n][1][i])%=mod;
    	printf("%d
    ",ans);	
    	return 0;
    }
    
  • 相关阅读:
    Shapefile文件数据库操作ArcEngine +C#
    INewFeedBack接口ArcGlobe
    如何获取免费Aster GDem数据
    FUCK EFS!!!!!
    5种方法解除开机密码[转]
    blobtracking references[转]
    cvMatND
    二值图像相似性[转]
    OpenCV中打印CvMat的元素
    视觉&图像处理相关链接
  • 原文地址:https://www.cnblogs.com/nosta/p/11040141.html
Copyright © 2020-2023  润新知