#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 42
#endif
const int mod = 1e9 + 7;
bool is(string a, string b) {
int n = a.size(), m = b.size();
for (int i = 0; i <= n - m; i++) {
if (a.substr(i, m) == b) {
return true;
}
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<vector<string>> s(n, vector<string>(k));
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
cin >> s[i][j];
}
}
vector<vector<int>> dp(n, vector<int>(k));
fill(dp[0].begin(), dp[0].end(), 1);
for (int i = 1; i < n; i++) {
for (int j = 0; j < k; j++) {
for (int r = 0; r < k; r++) {
if (is(s[i][j], s[i - 1][r])) {
dp[i][j] = (dp[i][j] + dp[i - 1][r]) % mod;
}
}
}
}
int res = 0;
for (int i = 0; i < k; i++) {
res = (res + dp[n - 1][i]) % mod;
}
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |