#include <bits/stdc++.h>
using namespace std;
const int N = 2e3+5,mod = 1e9+7;
typedef long long ll;
int n,k;
string a[N];
set<string> s;
map<string,int> sTOi;
int cnt,res[N];
int cb[N][N],dp[N][N];
int main()
{
cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
cin >> n >> k;
for (int i=0;i<n;i++)
cin >> a[i];
for (int i=0;i<n;i++)
sort(a[i].begin(),a[i].end());
for (int i=0;i<n;i++) s.insert(a[i]);
for (string u : s) sTOi[u] = ++cnt;
for (int i=0;i<n;i++) res[sTOi[a[i]]]++;
cb[0][0] = 1;
for (int i=1;i<=n;i++) for (int j=0;j<=i;j++) {
if (j==0) cb[i][j] = 1;
else {
cb[i][j] = cb[i-1][j-1] + cb[i-1][j];
cb[i][j] %= mod;
}
}
dp[0][0] = 1;
for (int i=1;i<=n;i++) for (int q=0;q<=k;q++) {
for (int j=0;j<=res[i];j++) {
ll x = j*(j-1);
x/= 2;
ll y;
y = cb[res[i]][j];
y %= mod;
if (q>=x) {
dp[i][q] = dp[i][q] + y*dp[i-1][q-x];
dp[i][q] %= mod;
}
}
}
cout << dp[n][k];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
13260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Incorrect |
10 ms |
13260 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |