HDU 3360 national treasures minimum point Overwrite for parity matching

Source: Internet
Author: User

Source: HDU 3360 national treasures

Question: If a [I] [J]! =-1 convert it to binary. A maximum of 12 digits represent the 12 positions in the graph of the question. If the corresponding position is 1, a guard can be placed there to hold a [I] [J]. location.

Train of Thought: overwrite the obviously dead minimum point to create an odd-even matching Graph

# Include <cstdio> # include <cstring> # include <vector> using namespace STD; const int maxn = 55; int vis [maxn * maxn]; int y [maxn * maxn]; vector <int> G [maxn * maxn]; int n, m; int A [maxn] [maxn]; int dir [12] [2] = {-1,-2,-2,-1,-2, 1,-1, 2, 1, 2, 1, 2,-1, 1,-2,-1, 0, 0, 1, 1, 0, 0,-1}; bool DFS (int u) {for (INT I = 0; I <G [u]. size (); I ++) {int v = G [u] [I]; If (vis [v]) continue; vis [v] = true; if (Y [v] = -1 | DFS (Y [v]) {Y [v] = u; return true;} return false;} int match () {int ans = 0; memset (Y,-1, sizeof (y); For (INT I = 0; I <n; I ++) {for (Int J = 0; j <m; j ++) {If (I + J) % 2) {memset (VIS, 0, sizeof (VIS); If (DFS (I * m + J )) ans ++ ;}}return ans ;}int main () {int CAS = 1; while (scanf ("% d", & N, & M) & (N | M) {for (INT I = 0; I <n; I ++) for (Int J = 0; j <m; j ++) scanf ("% d", & A [I] [J]); For (INT I = 0; I <n * m; I ++) g [I]. clear (); For (INT I = 0; I <n; I ++) {for (Int J = 0; j <m; j ++) {int x = A [I] [J]; If (x =-1) continue; For (int K = 0; k <12; k ++, x> = 1) {If (! X) break; If (! (X & 1) continue; int xx = I + dir [k] [0]; int YY = J + dir [k] [1]; if (XX <0 | XX> = n | YY <0 | YY> = m) continue; if (a [XX] [YY] =-1) continue; If (I + J) % 2) g [I * m + J]. push_back (XX * m + YY); elseg [XX * m + YY]. push_back (I * m + J) ;}} printf ("% d. % d \ n ", CAS ++, match ();} return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.