# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
456867 | ntabc05101 | Vještica (COCI16_vjestica) | C++14 | 114 ms | 1044 KiB |
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 mod = 1e9 + 7;
#define taskname ""
int main() {
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
int c[n][26];
memset(c, 0, sizeof(c));
string s;
for (int i = 0; i < n; i++) {
cin >> s;
for (auto& _: s) {
c[i][_ - 'a']++;
}
}
const int full_bit = 1 << n;
int dp[full_bit];
dp[0] = 0;
for (int msk = 1; msk < full_bit; msk++) {
int n_node = 0;
vector<int> _min(26, mod);
for (int i = 0; i < n; i++) {
if (msk >> i & 1) {
for (int j = 0; j < 26; j++) {
_min[j] = min(_min[j], c[i][j]);
}
}
}
for (int i = 0; i < 26; i++) {
n_node += _min[i];
}
if ((msk & -msk) == msk) {
dp[msk] = n_node;
}
else {
dp[msk] = mod;
for (int _msk = (msk - 1) & msk; _msk; _msk = (_msk - 1) & msk) {
dp[msk] = min(dp[msk], dp[_msk] + dp[msk ^ _msk] - n_node);
}
}
}
//cout << dp[2] << "\n";
cout << dp[full_bit - 1] + 1 << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |