Poj 2226 muddy field

Source: Internet
Author: User

Enhanced version 3041

Because the lawn cannot be covered by wooden boards, you need to deal with it more.

 

Since the wooden boards can only be placed horizontally or vertically, the first time the numbers of boards that can be placed horizontally and are not consecutive, and the second time the numbers of boards that can be placed vertically and are not consecutive

 

Think of a wooden board as a vertex and a muddy ground as an edge. A mud point corresponds to an edge, which is converted into a bipartite graph. The smallest vertex can be overwritten by all edges. The minimum vertex overwrites = the maximum number of matches.

 

Code:

# Include <iostream> using namespace STD; # define Max 1005 int link [Max], U [Max], W [Max] [Max], a [Max] [Max], B [Max] [Max]; char map [55] [55]; int NX, NY; int DFS (INT t) {for (INT I = 1; I <= NY; I ++) {If (! U [I] & W [T] [I]) {u [I] = 1; if (link [I] =-1 | DFS (link [I]) {link [I] = T; return 1 ;}} return 0 ;} int Hungary () {int I, num = 0; memset (link,-1, sizeof (Link); for (I = 1; I <= NX; I ++) {memset (u, 0, sizeof (u); num + = DFS (I);} return num;} int main () {int R, C, I, J; nx = ny = 0; scanf ("% d", & R, & C); getchar (); for (I = 1; I <= R; I ++) {for (j = 1; j <= C; j ++) {scanf ("% C", & map [I] [J]);} getchar () ;}for (I = 1; I <= r; I ++) {for (j = 1; j <= C; j ++) {If (Map [I] [J] = '*') {If (Map [I] [J-1] = '*') A [I] [J] = A [I] [J-1]; else a [I] [J] = + NX ;}} for (I = 1; I <= r; I ++) {for (j = 1; j <= C; j ++) {If (Map [I] [J] = '*') {If (Map [I-1] [J] = '*') B [I] [J] = B [I-1] [J]; else B [I] [J] = + + ny; W [A [I] [J] [B [I] [J] = 1 ;}} printf ("% d \ n", Hungary ()); 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.