#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
const int N = 2e6+5;
const int MOD = 1e9+7;
ll ans[55][1505];
string str[55][1505];
bool issubstr(string a, string b){
int n=a.length(), m=b.length();
for(int i=0; i<m-n+1; i++){
if(b.substr(i, n) == a) return 1;
}
return 0;
}
int main(){
int n, k;
cin >> n >> k;
for(int i=0; i<k; i++){
ans[0][i]=1;
}
for(int i=0; i<n; i++){
for(int j=0; j<k; j++){
cin >> str[i][j];
if(i > 0){
for(int h=0; h<k; h++){
if(issubstr(str[i-1][h], str[i][j])){
ans[i][j]=(ans[i][j]+ans[i-1][h])%MOD;
}
}
}
}
}
ll anss=0;
for(int i=0; i<k; i++){
anss=(anss+ans[n-1][i])%MOD;
}
cout << anss;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |