Submission #83307

#TimeUsernameProblemLanguageResultExecution timeMemory
83307fredbrMate (COCI18_mate)C++17
80 / 100
2072 ms42312 KiB
#include <bits/stdc++.h> using namespace std; const int maxm = 30; const int maxn = 2010; typedef long long ll; const ll mod = 1000000007; ll dp[maxm][maxm][maxn]; ll pchoose[maxn][maxn]; ll choose(ll n, ll k) { if (pchoose[n][k] >= 0) return pchoose[n][k]; return pchoose[n][k] = (choose(n-1, k) + choose(n-1, k-1)) % mod; } void init() { memset(pchoose, -1, maxn*maxn*8); for (int i = 0; i < maxn; i++) { pchoose[i][0] = 1; pchoose[i][i] = 1; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = s.size(); init(); for (int i = 0; i < n-1; i++) { for (int j = i+1; j < n; j++) { for (int k = 0; k <= i; k++) { dp[s[i]-'a'][s[j]-'a'][k+2] += choose(i, k); dp[s[i]-'a'][s[j]-'a'][k+2] %= mod; } } } int q; cin >> q; while (q--) { int num; char a, b; cin >> num >> a >> b; cout << dp[a-'a'][b-'a'][num] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...