The main idea: on a map of n * m there are k garbage, asked to send a few robots to complete the pick.
The robot's walking route has been planned, only from the left to the right down, and can only move forward, can not go backwards
Problem-solving ideas: Divide all points into two point sets, the relationship between points set is whether you can go from this point to another point, if possible, then the relationship exists
#include <cstdio>#include <cstring>#include <vector>using namespace STD;Const intN = +;structPoint {intx, y;} P[n];intVis[n], link[n], CNT; vector<int>G[n];BOOLJudge (Point A, point B) {if(b.y >= a.y && b.x >= a.x)return true;return false;}voidInit () {cnt =1; while(scanf("%d%d", &p[cnt].x, &p[cnt].y)) {if(p[cnt].x = =0&& P[cnt].y = =0) Break; cnt++; } for(inti =0; I < CNT; i++) {g[i].clear (); for(intj =0; J < CNT; J + +) {if(I! = J && judge (P[i], p[j])) G[i].push_back (j); } }memset(Link,-1,sizeof(link));}BOOLDfsintu) { for(inti =0; I < g[u].size (); i++) {intv = g[u][i];if(Vis[v])Continue; VIS[V] =1;if(Link[v] = =-1|| DFS (Link[v])) {Link[v] = u;return true; } }return false;}voidHungary () {intAns =0; for(inti =0; I < CNT; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", Cnt-ans);}intMain () { while(scanf("%d%d", &p[0].x, &p[0].Y)! = EOF) {if(p[0].x = =-1&& p[0].y = =-1) Break;if(p[0].x = =0&& p[0].y = =0) {printf("0\n");Continue; } init (); Hungary (); }return 0;}
POJ-1548 Robots The minimum path coverage of the binary graph