Hdu1150-machine Schedule (minimum point coverage)

Source: Internet
Author: User

Minimum vertex overlay for a binary graph: with a minimum of points, each edge is associated with at least one point.
Maximum number of matches = minimum point coverage (Konig theorem)

Water problem ...

Suddenly found my previous Hungarian algorithm template has a problem ... Because here the point on the left is 1~n, the point on the right is 1~m, so there are different points marking is the same, pay attention!

Because the algorithm itself is O (n^2), so the data will not be very large, rest assured with the adjacency matrix to save it ...

If a side has 0, then do not need to add in, each product should only appear once, otherwise it is wrong ... I thought for a long time, because the topic did not say that each product only appears once ...

Hdu1150#include <cstdio>  #include <cstring>  #include <iostream>  using namespace std ; const int n = 105;int n, m, K;bool mp[n][n];int match[n];bool used[n];bool find (int u) {for (int v = 0; v < m; ++v) {i F (Mp[u][v] &&!used[v]) {Used[v] = true;if (Match[v] = = 1 | | find (MATCH[V])) {Match[v] = U;return true;}} return false;} int Hungary () {memset (match,-1, sizeof match), int ans = 0;for (int i = 0; i < n; ++i) {memset (used, false, sizeof used ); if (find (i)) ++ans;} return ans;} int main () {//freopen ("in", "R", stdin) and while (~SCANF ("%d", &n) && N) {scanf ("%d%d", &m, &k); int u, v; Memset (MP, false, sizeof MP), while (k--) {scanf ("%*d%d%d", &u, &v), if (!u | |!v) CONTINUE;MP[U][V] = true;} printf ("%d\n", Hungary ());} return 0;}

  

Hdu1150-machine Schedule (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.