This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |