HDU 1083 simple binary match courses

Source: Internet
Author: User

Question http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1083

This is a simple question of Maximizing matching.

There are two methods

AC1

# Include <iostream> # include <cstring> # include <cstdio> using namespace STD; bool map [101] [301]; bool mark [301]; int CX [101], CY [301]; // CX indicates how many courses Cy indicates students Oh int P, N; int findpath (int u) // find the augmented path Oh {int I; for (I = 1; I <= N; I ++) {If (Map [u] [I] &! Mark [I]) // pay attention to the U location {mark [I] = 1; if (CY [I] =-1 | findpath (CY [I]) {CY [I] = u; CX [u] = I; return 1 ;}}return 0 ;}void maxmatch () // find the maximum match. {int I, j; int res = 0; for (I = 1; I <= P; I ++) CX [I] =-1; for (j = 1; j <= N; j ++) CY [J] =-1; for (I = 1; I <= P; I ++) {If (CX [I] =-1) {for (j = 1; j <= N; j ++) MARK [J] = 0; res + = findpath (I) ;}} if (RES >=p) {cout <"yes" <Endl; return ;} else cout <"no" <Endl;} int main () {int I, J, K, M; CIN> K; while (k --) {memset (MAP, false, sizeof (MAP); CIN> P> N; for (I = 1; I <= P; I ++) {CIN> J; For (int h = 1; H <= J; H ++) {CIN> m; Map [I] [m] = 1 ;}} maxmatch () ;}return 0 ;}

Ac2

# Include <iostream> # include <cstring> # include <cstdio> using namespace STD; bool map [301] [301]; bool mark [301]; int link [301]; // CX indicates the number of courses. Cy indicates the number of students. Int P, N; int findpath (int u) {int I; for (I = 1; I <= N; I ++) {If (Map [u] [I] &! Mark [I]) {mark [I] = 1; // is it CX or Cy? If (! Link [I] | findpath (link [I]) {link [I] = u; return 1 ;}} return 0 ;}void maxmatch () {int I, j; int res = 0; For (j = 1; j <= N; j ++) link [J] = 0; for (I = 1; I <= P; I ++) {for (j = 1; j <= N; j ++) MARK [J] = 0; Res + = findpath (I );} if (RES> = P) {cout <"yes" <Endl; return;} else cout <"no" <Endl;} int main () {int I, J, K, M; CIN> K; while (k --) {memset (MAP, false, sizeof (MAP); memset (link, false, sizeof (Link); CIN> P> N; for (I = 1; I <= P; I ++) {CIN> J; for (int h = 1; H <= J; H ++) {CIN> m; Map [I] [m] = 1 ;}} maxmatch (); // cout <"ddddddddddd1" <Endl;} 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.