Submission #476604

#TimeUsernameProblemLanguageResultExecution timeMemory
476604mychecksedadAnagramistica (COCI21_anagramistica)C++17
10 / 110
19 ms19284 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define pb push_back #define all(x) x.begin(), x.end() ll MOD = 1e9+7; const int N = 2010, M = 1e5+10, F = 2147483646, K = 20; int n, k, c[N][N], dp[N][N]; string s[N]; map<string, int> ms; void precalc(){ for(int i = 0; i < N; i++) c[i][0] = 1, c[0][i] = 0; for(int i = 1; i < N; i++){ for(int j = 1; j <= i; j++){ //c(n, k) = c(n - 1, k - 1) + c(n - 1, k) if(i==j) c[i][j] = 1; else c[i][j] = (c[i - 1][j - 1] + c[i - 1][j])%MOD; } } } int main(){ cin.tie(0); ios::sync_with_stdio(0); cin >> n >> k; precalc(); for(int i = 0; i < n; i++){ cin >> s[i]; sort(all(s[i])); ++ms[s[i]]; } for(int j = 0; j <= n; j++) for(int i = 0; i <= k; i++) dp[j][i] = 0; dp[0][0] = 1; int cur = 1; ll f = 0; for(auto kk: ms){ ll x = kk.second; // for(int i = 0; i <= k; i++) dp[cur][i] = dp[cur-1][i]; for(int j = 0; j <= x && j * (j - 1) / 2 <= k; j++) for(int i = k; i >= 0; --i){ if(i >= j * (j - 1) / 2){ (dp[cur][i] += (dp[cur - 1][i - j * (j - 1) / 2] * c[x][j])) %= MOD; // cout << cur << ' ' << i << ' ' << dp[cur][i] << '\n'; } } // cout << kk.first << '\n'; ++cur; } cout << dp[cur - 1][k]; return 0; }

Compilation message (stderr)

anagramistica.cpp: In function 'int main()':
anagramistica.cpp:39:8: warning: unused variable 'f' [-Wunused-variable]
   39 |     ll f = 0;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...