This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
const int N = 100 + 2;
const int MOD = 1e9 + 7;
int main() {
#ifdef judge
ifstream cin("input.txt");
#endif // judge
ios_base :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
int n , k;
cin >> n >> k;
string full[n][k] , pref[n][k] , suf[n][k];
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
cin >> full[i][j];
if (i > 0) {
pref[i][j] = full[i][j].substr(0 , i);
suf[i][j] = full[i][j].substr(1 , i);
}
}
}
vector<vector<int> > dp(n , vector<int>(k , 0));
for (int j = 0; j < k; j++) {
dp[0][j] = 1;
}
for (int i = 1; i < n; i++) {
for (int cur = 0; cur < k; cur++) {
for (int prev = 0; prev < k; prev++) {
if (full[i - 1][prev] == pref[i][cur] || full[i - 1][prev] == suf[i][cur]) {
dp[i][cur] += dp[i - 1][prev];
dp[i][cur] %= MOD;
}
}
}
}
int ans = 0;
for (int j = 0; j < k; j++) {
ans += dp[n - 1][j];
ans %= MOD;
}
cout << ans << '\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... |