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;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |