TC的插件突然不见了。。游戏体验极差= =
呜呜呜插件真好QAQ

我们可以枚举模板串的长度,然后就可以知道子矩阵中的每一个位置对应模板串的哪一位了。要判断这个长度是否可行,可以把串中的出现过的每一位记录下来。有些位置可能没有出现,那就是随便选。

#include <bits/stdc++.h>
using namespace std;
const int p=1e9+9;
const int N=10001;
int a[N],sum,n,m;
long long mul[N];

class CharacterBoard2 {
public:
    long long countGenerators( vector <string> s, int w, int i0, int j0 );
};

void init(){
    mul[0]=1;
    for(int i=1;i<N;i++) mul[i]=mul[i-1]*26%p;
}

long long solve(int l,vector<string> s,int i0,int j0,int ww){
    for(int i=0;i<n;i++)
     for(int j=0;j<m;j++){
        int w=((i+i0)*ww+j+j0)%l;
        if (a[w]==0) sum++,a[w]=s[i][j];
        if (a[w]!=s[i][j]) return 0;
     }
    return mul[l-sum];
}

long long CharacterBoard2::countGenerators( vector <string> s, int w, int i0, int j0 ) {
    init();
    long long ans=0;
    n=s.size();m=s[0].size();
    for(int l=1;l<=w;l++){
        for(int i=0;i<l;i++) a[i]=0;
        sum=0;
        ans=(ans+solve(l,s,i0,j0,w))%p;
    }
    return ans;
}