Submission #223215

#TimeUsernameProblemLanguageResultExecution timeMemory
223215shenxyTrener (COCI20_trener)C++11
110 / 110
135 ms16504 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...