#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 |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8272 KB |
Output is correct |
2 |
Correct |
6 ms |
10196 KB |
Output is correct |
3 |
Correct |
7 ms |
12208 KB |
Output is correct |
4 |
Correct |
33 ms |
14156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
8272 KB |
Output is correct |
7 |
Correct |
6 ms |
10196 KB |
Output is correct |
8 |
Correct |
7 ms |
12208 KB |
Output is correct |
9 |
Correct |
33 ms |
14156 KB |
Output is correct |
10 |
Correct |
13 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
3 ms |
6356 KB |
Output is correct |
13 |
Correct |
4 ms |
6356 KB |
Output is correct |
14 |
Correct |
8 ms |
10184 KB |
Output is correct |
15 |
Correct |
8 ms |
10188 KB |
Output is correct |
16 |
Correct |
10 ms |
14164 KB |
Output is correct |
17 |
Correct |
11 ms |
14156 KB |
Output is correct |
18 |
Correct |
9 ms |
14164 KB |
Output is correct |