#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
const ll mod = 1'000'000'007;
int ad(ll a, ll b)
{
return (a+b)%mod;
}
int mul(ll a, ll b)
{
return (a*b)%mod;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
string s[n];
vi val{0};
for(int i = 0; i < n; i++)
{
cin >> s[i];
sort(s[i].begin(), s[i].end());
}
sort(s, s+n);
for(int i = 0; i < n; i++)
{
if(i == 0 || s[i] != s[i-1]) val.push_back(1);
else val.back()++;
}
int ch[1+n][1+n];
for(int i = 0; i <= n; i++)
{
ch[i][0] = ch[i][i] = 1;
for(int j = 1; j < i; j++)
ch[i][j] = ch[i-1][j] + ch[i-1][j-1];
}
int z = int(val.size())-1;
vvi dp(1+z, vi(1+k, 0));
dp[0][0] = 1;
for(int i = 1; i <= z; i++)
{
for(int j = 0; j <= k; j++)
{
for(int c = 0; j - (c*(c-1)/2) >= 0 && c <= val[i]; c++)
{
dp[i][j] = ad(dp[i][j], mul(ch[val[i]][c], dp[i-1][j - (c*(c-1))/2]));
}
}
}
cout << dp[z][k] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6480 KB |
Output is correct |
2 |
Correct |
5 ms |
9168 KB |
Output is correct |
3 |
Correct |
7 ms |
12360 KB |
Output is correct |
4 |
Correct |
9 ms |
16064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
4 ms |
6480 KB |
Output is correct |
7 |
Correct |
5 ms |
9168 KB |
Output is correct |
8 |
Correct |
7 ms |
12360 KB |
Output is correct |
9 |
Correct |
9 ms |
16064 KB |
Output is correct |
10 |
Correct |
2 ms |
1900 KB |
Output is correct |
11 |
Correct |
1 ms |
1720 KB |
Output is correct |
12 |
Correct |
2 ms |
4288 KB |
Output is correct |
13 |
Incorrect |
3 ms |
4304 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |