Hoj 2472 IR-Lab

Source: Internet
Author: User

/*

Question:

 

On-duty questions: give everyone their spare time and ask if they can schedule a person on duty at every time.

 

Analysis:

The problem of binary matching is illustrated by the link between a person and his spare time. Then the hungry algorithm is simple.

*/

 

# Include
<Iostream>

 

# Include
<Cstring>

 

# Include
<Cstdio>

 

Using namespace
Std;

 

# Define X 22

 

Bool
G [X] [X], use [X];

 

Int
Xm [X], ym [X], k, p;

 

Bool dfs (int u)

 

{

 

For (int v = 0; v <k; v ++)

 

If (g [u] [v] &! Use [v])

 

{

 

Use [v] = true;

 

If (ym [v] =-1 | dfs (ym [v])

 

{

 

Xm [u] = v;

 

Ym [v] = u;

 

Return true;

 

}

 

}

 

Return false;

 

}

 

Int hungry ()

 

{

 

Int ret = 0;

 

Memset (xm,-1, sizeof (xm ));

 

Memset (ym,-1, sizeof (ym ));

 

For (int u = 0; u <p; u ++)

 

If (xm [u] =-1)

 

{

 

Memset (use, false, sizeof (use ));

 

If (dfs (u ))

 

Ret ++;

 

}

 

Return ret;

 

}

 

Int main ()

 

{

 

Freopen ("sum. in", "r", stdin );

 

Freopen ("sum. out", "w", stdout );

 

While (cin> k> p, k | p)

 

{

 

Int t, x;

 

Memset (g, false, sizeof (g ));

 

For (int I = 0; I <p; I ++)

 

{

 

Scanf ("% d", & t );

 

While (t --)

 

{

 

Scanf ("% d", & x );

 

G [I] [x] = true; // This person is connected to his/her spare time.

 

}

 

}

 

If (hungry () = k) // if yes

 

Printf ("yes \ n ");

 

Else

 

Printf ("no \ n ");

 

// Printf ("% d \ n", hungry ());

 

}

 

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.