# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
304959 | BeanZ | Vještica (COCI16_vjestica) | C++14 | 1259 ms | 1272 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define endl '\n'
const int N = 1e5 + 5;
ll cnt[20][26], dp[(1 << 16) + 1];
ll n;
ll cal(ll mask){
ll ans = 0;
for (int j = 0; j < 26; j++){
ll res = 1e9;
for (int i = 0; i < n; i++){
if (mask & (1 << i)){
res = min(res, cnt[i][j]);
}
}
ans = ans + res;
}
return ans;
}
ll DP(ll mask){
if (__builtin_popcount(mask) == 1) return cal(mask);
if (dp[mask] != -1) return dp[mask];
ll prev = cal(mask);
dp[mask] = 1e9;
for (int i = (mask - 1) & mask; i; i = (i - 1) & mask){
dp[mask] = min(dp[mask], DP(i) + DP(mask ^ i) - prev);
}
return dp[mask];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> n;
for (int i = 0; i < n; i++){
string s;
cin >> s;
for (int j = 0; j < s.length(); j++){
cnt[i][s[j] - 'a']++;
}
}
memset(dp, -1, sizeof(dp));
cout << DP((1 << n) - 1) + 1;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |