#include <bits/stdc++.h>
using namespace std;
#define task "main"
#define F first
#define S second
#define ii pair<int, int>
#define il pair<int, long long>
#define li pair<long long, int>
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
const int MAX_N = (int)2e3 + 3;
const int MOD = (int)1e9 + 7;
const int base = 311;
int n, k;
string s[MAX_N];
int cnt[27];
int hsh[MAX_N];
int a[MAX_N];
int C[MAX_N][MAX_N];
int dp[MAX_N][MAX_N];
void add(int &x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
void solve() {
cin >> n >> k;
FOR(i, 1, n) cin >> s[i];
FOR(i, 1, n) {
FOR(c, 1, 26) cnt[c] = 0;
for (int c : s[i]) cnt[c - 'a' + 1]++;
hsh[i] = 0;
FOR(c, 1, 26) hsh[i] = (1LL * hsh[i] * base % MOD + cnt[c]) % MOD;
}
sort(hsh + 1, hsh + n + 1);
int i = 1, m = 0;
while (i <= n) {
int j = i;
while (j <= n && hsh[j] == hsh[i]) j++;
a[++m] = (j - i);
i = j;
}
FOR(i, 0, n) C[0][i] = 1;
FOR(i, 1, n) FOR(j, 1, i)
C[j][i] = (1LL * C[j][i - 1] + C[j - 1][i - 1]) % MOD;
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
FOR(i, 1, m) FOR(j, 0, k) {
int x = 0;
while (x <= a[i] && x * (x - 1) / 2 <= j) {
add(dp[i][j], 1LL * dp[i - 1][j - x * (x - 1) / 2] * C[x][a[i]] % MOD);
x++;
}
}
cout << dp[m][k];
}
int32_t main() {
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
bool multitest = 0;
int numTest = 1;
if (multitest) cin >> numTest;
while (numTest--) {
solve();
}
return 0;
}
/* Lak lu theo dieu nhac!!!! */
Compilation message (stderr)
anagramistica.cpp: In function 'int32_t main()':
anagramistica.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
anagramistica.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |