#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]]]++;
for (int i=0;i<=n;i++) cerr << res[i] << "\n";
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;
}
}
for (int i=0;i<=n;i++) {
for (int j=0;j<=i;j++) cerr << cb[i][j] << " ";
cerr << "\n";
}
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;
}
}
cerr << i << " " << q << " "<<dp[i][q] << "\n";
}
cout << dp[n][k];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1074 ms |
11700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
4 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Execution timed out |
1074 ms |
11700 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |