#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e3+5, MOD = 1e9+7;
int fact[N];
int fastpow(int n, int p){
int res = 1;
while(p){
if(p&1) res = res * n % MOD;
n = n * n % MOD;
p >>= 1;
}
return res;
}
void init(){
fact[0] = 1;
for(int i = 1;i < N;i++)
fact[i] = fact[i-1] * i % MOD;
}
int nCr(int n, int r){
if(n < r) return 0;
return fact[n]*fastpow(fact[r],MOD-2)%MOD*fastpow(fact[n-r],MOD-2)%MOD;
}
signed main(){
fastio
init();
int n,k;
cin >> n >> k;
map<string,int> m;
for(int i = 0;i < n;i++){
string s;
cin >> s;
sort(s.begin(),s.end());
m[s]++;
}
vector<int> v;
v.push_back(0);
for(auto [a,b] : m){
v.push_back(b);
}
n = v.size();
int dp[n][k+1] = {};
dp[0][0] = 1;
for(int a = 1;a < n;a++){
for(int j = k;~j;j--){
dp[a][j] = dp[a-1][j];
}
int x = v[a];
for(int i = 1;i <= x;i++){
int tmp = i*(i-1)/2;
for(int j = k;~j;j--){
if(j < tmp) break;
dp[a][j] = (dp[a][j] + dp[a-1][j-tmp]*nCr(x,i)) % MOD; \
}
}
}
cout << dp[n-1][k] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
30 ms |
716 KB |
Output is correct |
11 |
Correct |
12 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
12 ms |
340 KB |
Output is correct |
14 |
Correct |
20 ms |
472 KB |
Output is correct |
15 |
Correct |
8 ms |
332 KB |
Output is correct |
16 |
Correct |
87 ms |
1816 KB |
Output is correct |
17 |
Correct |
144 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |