1. 程式人生 > >BZOJ 1080: [SCOI2008]劣質編碼

BZOJ 1080: [SCOI2008]劣質編碼

技術 wid mes AC == its ++i In DC

這題我會暴力。。。如果時限 1e9 的話就可以過啦技術分享圖片

這題 clj 也會暴力。。。然後他就秒 A 了。。。

(果然是蒟蒻 vs 大神)技術分享圖片

大神的暴力簡直不可用語言來描述了。。。

#include <bits/stdc++.h>

using namespace std;

const int N = 55;
string str[N];
int n;
vector<int> u, v, w;
map< vector<int>, int > Hash;
queue< vector<int> > q;

int main() {
    ios::sync_with_stdio(
false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> str[i]; if (str[i] == "") { cout << 0 << endl; return 0; } else { u.push_back(i << 6); } } Hash[u] = 0; q.push(u);
while (!q.empty()) { u = q.front(); q.pop(); int h = Hash[u]; for (int c = 0; c <= 1; c++) { int cnt = 0; v.clear(); for (int i = 0; i < u.size(); i++) { int obj = u[i] >> 6, idx = u[i] & 63;
if (str[obj][idx] == c) { if (++idx == str[obj].size()) { ++cnt; for (int j = 1; j <= n; j++) { v.push_back(j << 6); } } else { v.push_back(obj << 6 | idx); } } } if (cnt >= 3) { cout << h + 1 << endl; return 0; } sort(v.begin(), v.end()); if (!v.empty() && !Hash[v]) { Hash[v] = h + 1; q.push(v); } } } cout << -1 << endl; return 0; }

小心臟都受不了了呢(≧▽≦)

正解是一種奇妙的 DP,但是我現在太菜了看不懂 QWQ

BZOJ 1080: [SCOI2008]劣質編碼