Submission #421079

#TimeUsernameProblemLanguageResultExecution timeMemory
421079ChaskaAnagramistica (COCI21_anagramistica)C++11
10 / 110
1074 ms11700 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...