#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define all(x) x.begin(), x.end()
ll MOD = 1e9+7;
const int N = 2010, M = 1e5+10, F = 2147483646, K = 20;
int n, k, c[N][N], dp[N][N];
string s[N];
map<string, int> ms;
void precalc(){
for(int i = 0; i < N; i++) c[i][0] = 1, c[0][i] = 0;
for(int i = 1; i < N; i++){
for(int j = 1; j <= i; j++){
//c(n, k) = c(n - 1, k - 1) + c(n - 1, k)
if(i==j) c[i][j] = 1;
else c[i][j] = (c[i - 1][j - 1] + c[i - 1][j])%MOD;
}
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
cin >> n >> k;
precalc();
for(int i = 0; i < n; i++){
cin >> s[i];
sort(all(s[i]));
++ms[s[i]];
}
for(int j = 0; j <= n; j++) for(int i = 0; i <= k; i++) dp[j][i] = 0;
dp[0][0] = 1;
int cur = 1;
ll f = 0;
for(auto kk: ms){
ll x = kk.second;
// for(int i = 0; i <= k; i++) dp[cur][i] = dp[cur-1][i];
for(int j = 0; j <= x && j * (j - 1) / 2 <= k; j++)
for(int i = k; i >= 0; --i){
if(i >= j * (j - 1) / 2){
(dp[cur][i] += (dp[cur - 1][i - j * (j - 1) / 2] * c[x][j])) %= MOD;
// cout << cur << ' ' << i << ' ' << dp[cur][i] << '\n';
}
}
// cout << kk.first << '\n';
++cur;
}
cout << dp[cur - 1][k];
return 0;
}
Compilation message
anagramistica.cpp: In function 'int main()':
anagramistica.cpp:39:8: warning: unused variable 'f' [-Wunused-variable]
39 | ll f = 0;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14320 KB |
Output is correct |
2 |
Correct |
17 ms |
14288 KB |
Output is correct |
3 |
Correct |
16 ms |
14284 KB |
Output is correct |
4 |
Correct |
17 ms |
14288 KB |
Output is correct |
5 |
Correct |
16 ms |
14288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
19284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14320 KB |
Output is correct |
2 |
Correct |
17 ms |
14288 KB |
Output is correct |
3 |
Correct |
16 ms |
14284 KB |
Output is correct |
4 |
Correct |
17 ms |
14288 KB |
Output is correct |
5 |
Correct |
16 ms |
14288 KB |
Output is correct |
6 |
Incorrect |
19 ms |
19284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |