Submission #682632

#TimeUsernameProblemLanguageResultExecution timeMemory
682632Alex_tz307Anagramistica (COCI21_anagramistica)C++17
110 / 110
10 ms14292 KiB
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 2e3; int dp[1 + N], C[1 + N][1 + N]; void addSelf(int &x, int y) { x += y; if (x >= mod) { x -= mod; } } int add(int x, int y) { addSelf(x, y); return x; } int mult(int x, int y) { return (int64_t)x * y % mod; } void precalc(int n) { for (int i = 0; i <= n; ++i) { C[i][0] = 1; for (int j = 1; j <= i; ++j) { C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; precalc(n); unordered_map<string, int> cnt; for (int i = 0; i < n; ++i) { string word; cin >> word; sort(word.begin(), word.end()); cnt[word] += 1; } dp[0] = 1; for (const auto &it : cnt) { int subSize = it.second; for (int pairs = k; pairs >= 0; --pairs) { for (int take = 1; take <= subSize && C[take][2] <= pairs; ++take) { addSelf(dp[pairs], mult(dp[pairs - C[take][2]], C[subSize][take])); } } } cout << dp[k] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...