POJ 2724 Purifying Machine
Topic links
Test instructions: This question test instructions a bit not understand. Look at the other people's puzzle,
Gives 01 strings with a m string length of N.
Some strings may include , such a string can represent two strings, 1 and 0.
Repeated calculation of one. For example, in question 01
100
011
It represents four 01 strings.
001
101
100
011
Now we need to wipe out all 01 of them, in two ways:
Kill a String 11 times.
2 Suppose the difference between the two strings is that only one word can destroy the two strings at the same time.
Ask at least how many operations can kill all 01 strings
Idea: Save the existing binary number and then go heavy. Then build the edge, binary difference 1-bit edge. Then we ask for the maximum independent set, n-Maximum number of matches
Code:
#include <cstdio> #include <cstring> #include <vector> #include <algorithm>using namespace std; const int N = 2005;int S[n], N, M;char str[15];vector<int> g[n];int bitcount (int x) {return x = = 0? x:bitcount (x& gt;>1) + (x&1);} int left[n], vis[n];bool dfs (int u) {for (int i = 0; i < g[u].size (); i++) {int v = g[u][i];if (Vis[v]) Continue;vis[v] = 1;if (Left[v] = = 1 | | DFS (LEFT[V)) {Left[v] = U;return true;}} return false;} int Hungary () {int ans = 0;memset (left,-1, sizeof (left)), for (int i = 0; i < n; i++) {memset (Vis, 0, sizeof (VIS)); DFS (i)) ans++;} return ans;} int main () {while (~scanf ("%d%d", &n, &m) && n) {n = 0;for (int i = 0; i < m; i++) {scanf ("%s", str); T len = strlen (str); S[n] = 0;for (int j = len-1; J >= 0; j--) s[n] = s[n] * 2 + (str[j]! = ' 0 '); n++;for (int j = 0; j < Len; J + +) {if (str[j] = = ' * ') {s[n] = S[n-1];s[n] ^= (1<<j); n++;}}} Sort (s, S + N); int tmp = 1;for (int i = 1; i < n; i++) if (s[I] = s[i-1]) s[tmp++] = S[i];n = tmp;for (int i = 0; i < n; i++) {g[i].clear (); for (int j = 0; J < i; J + +) {if (b Itcount (S[i]^s[j]) <= 1) {g[i].push_back (j); G[j].push_back (i);}}} printf ("%d\n", N-hungary ()/2);} return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
POJ 2724 purifying Machine (maximum independent set)