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 <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
const long long mod = 1000000007;
map<string, long long> cnt, dptable;
long long dp(string name) {
if (cnt[name] == 0) return 0;
if (name.size() == 1) return 1;
if (dptable.find(name) != dptable.end()) return dptable[name];
long long ans = 0;
string subs[2];
for (int i = 0; i < 2; ++i) subs[i] = name.substr(i, name.size() - 1);
for (int i = 0; i <= (subs[0] != subs[1]); ++i) {
ans += dp(subs[i]) * cnt[subs[i]];
ans %= mod;
}
return dptable[name] = ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, K;
cin >> N >> K;
string names[N][K];
for (int i = 0; i < N; ++i) {
for (int j = 0; j < K; ++j) {
cin >> names[i][j];
++cnt[names[i][j]];
}
}
long long ans = 0;
for (int i = 0; i < K; ++i) ans = (ans + dp(names[N - 1][i])) % mod;
printf("%lld", ans);
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... |