POJ-2226 Muddy fields Binary map minimum point coverage

Source: Internet
Author: User

The main topic: there is an n * M ranch, pasture land is divided into two kinds, one is very muddy, one is relatively dry
Because the animals in the ranch don't like muddy places, the ranchers want to use something to cover up the muddy areas.
Ranchers use a 1-width, unlimited length of material to cover these muddy places.
Ask at least how many times this material must be used before you can cover up all the muddy areas

Problem-solving ideas: Just start without trial on the topic, the above is what I started to think of the test instructions, so I set the thinking, thought that the problem and POJ-3041 asteroids, so WA took two rounds
Later looked carefully, see missing a condition, that is not to the relatively dry place also to cover out. So the difference between the two questions came out, that is, the construction point set is not the same, but the idea of solving the problem is the same, to find the smallest point coverage can be
How to construct a point set, as long as it is not continuous, is different, so you have to reset a variable to calculate how many rows and how many columns

#include <cstdio>#include <vector>#include <cstring>using namespace STD;Const intN =1010;Const intMAXN = -; vector<int>Row[n];intN, M, Num_r, NEW_ROW[MAXN][MAXN], NEW_COL[MAXN][MAXN], vis[n], link[n];CharSTR[MAXN][MAXN];voidInit () {Num_r =1; for(inti =1; I <= N; i++)scanf('%s ', Str[i]);BOOLFlag for(inti =1; I <= N; i++) {if(!flag) num_r++; Flag =true; for(intj =0; J < M; J + +) {if(Str[i][j] = =' * ') {new_row[i][j+1] = Num_r; Flag =false; }Else if(Str[i][j] = ='. '&&!flag) {num_r++; Flag =true; }        }    } for(inti =1; I <= Num_r; i++) row[i].clear ();intCNT =1; for(inti =0; I < m; i++) {if(!flag) cnt++; Flag =true; for(intj =1; J <= N; J + +) {if(Str[j][i] = =' * ') {new_col[j][i+1] = CNT; Flag =false; }Else if(Str[j][i] = ='. '&&!flag) {flag =true;            cnt++; }        }    } for(inti =1; I <= N; i++) for(intj =1; J <= M; J + +)if(str[i][j-1] ==' * ') Row[new_row[i][j]].push_back (New_col[i][j]);memset(Link,0,sizeof(link));}BOOLDfsintu) { for(inti =0; I < row[u].size (); i++) {if(Vis[row[u][i]])Continue; Vis[row[u][i]] =1;if(!link[row[u][i] | | DFS (LINK[ROW[U][I])) {Link[row[u][i]] = u;return true; }    }return false;}voidHungary () {intAns =0; for(inti =1; I <= Num_r; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", ans);}intMain () { while(scanf("%d%d", &n, &m)! = EOF) {init ();    Hungary (); }return 0;}

POJ-2226 Muddy fields Binary map minimum point coverage

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.