PKU 3041 asteroids-minimum vertex coverage of the Binary Graph Model of the row and column

Source: Internet
Author: User

Theme:

In the space of N * n, there are K minor planets. Using super weapons, you can clean up one row or one column of all minor planets at a time. however, the super weapon is very expensive. The sky chart is displayed, and the minimum number of weapons required to be used can clear all the minor planets. n <500, k <10,000

Analysis:

Classic lineColumn model conversionForBipartite Graph ModelZju1002 and pku2226 can also be converted.

Use rows and columns as the nodes on the left and right of the Bipartite Graph. if there is an minor on the map (I, j), an edge is connected between the I node on the left and J node on the right of the Bipartite Graph.

When this model is mapped to the question, a weapon is used to select a vertex V on the left or right of the Bipartite Graph. the edge connected to V indicates all the minor planets in the V row (or column. the question is converted to: select the least vertex in the bipartite graph, so that at least one endpoint of all edges is overwritten.

This is the classic bipartite graph.Minimum point coverage.

AccordingKönig Theorem: Bipartite GraphMinimum vertex overwrite = maximum number of matches.

Therefore, the question is convertedMaximum matching of a Bipartite Graph, It is a perfect solution.

By the way, the zju1002 bipartite graph model cannot directly use rows or columns as the vertices of the Bipartite Graph, but needsSplit point. For more information, see my other solution report.

Http://blog.csdn.net/tiaotiaoyly/archive/2008/10/23/3122893.aspx

 

  1. /*
  2. Pku3041 Asteroids
  3. */
  4. # Include <stdio. h>
  5. # Include <memory. h>
  6. # Define CLR (a) memset (A, 0, sizeof ())
  7. # Define n 505
  8. Int find (int I, int M, int G [] [N], int mat [], int tmat []) {
  9. Int V, J;
  10. For (j = 0; j <m; j ++ ){
  11. If (G [I] [J] & tmat [J] = 0 ){
  12. Tmat [J] = 1; V = mat [J]; MAT [J] = I;
  13. If (V =-1 | find (v, M, G, mat, tmat) return 1;
  14. Mat [J] = V;
  15. }
  16. }
  17. Return 0;
  18. }
  19. Int match (int g [] [N], int N, int M, int mat []) {
  20. Int I, K = 0, tmat [N];
  21. For (I = 0; I <m; I ++) mat [I] =-1;
  22. For (I = 0; I <n; I ++ ){
  23. CLR (tmat); k + = find (I, m, G, mat, tmat );
  24. }
  25. Return K;
  26. }
  27. Int n, m;
  28. Int a [n] [N];
  29. Int mat [N];
  30. Int main ()
  31. {
  32. Int I, J, K;
  33. While (scanf ("% d", & N, & M )! = EOF ){
  34. // Init
  35. CLR ();
  36. // Input
  37. For (k = 0; k <m; k ++ ){
  38. Scanf ("% d", & I, & J );
  39. I --; j --;
  40. A [I] [J] = 1;
  41. }
  42. // Output
  43. K = match (A, N, N, mat );
  44. Printf ("% d/N", k );
  45. }
  46. Return 0;
  47. }

 

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.