#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 2020;
int n, k;
string s[MAX];
vector<int> a;
int dp[MAX][MAX];
int cnt[MAX][MAX];
map<vector<int>, int> myMap;
void add(int &x, const int &y)
{
x += y;
if (x >= MOD)
{
x -= MOD;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cnt[0][0] = 1;
for (int i = 1; i <= 2000; ++i)
{
cnt[0][i] = cnt[i][i] = 1;
for (int j = 1; j < i; ++j)
{
add(cnt[j][i], cnt[j - 1][i - 1]);
add(cnt[j][i], cnt[j][i - 1]);
}
}
cin >> n >> k;
for (int i = 1; i <= n; ++i)
{
cin >> s[i];
vector<int> cnt(26, 0);
for (char &c : s[i])
++cnt[c - 'a'];
++myMap[cnt];
}
for (auto x : myMap)
a.push_back(x.second);
dp[0][0] = 1;
for (int i = 0; i < int(a.size()); ++i)
{
for (int j = 0; j <= k; ++j)
{
if (dp[i][j] == 0)
continue;
for (int l = 0; l <= a[i]; ++l)
{
if (j + l * (l - 1) / 2 > k)
break;
add(dp[i + 1][j + l * (l - 1) / 2], 1LL * dp[i][j] * cnt[l][a[i]] % MOD);
}
}
}
cout << dp[int(a.size())][k];
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... |