Hoj 3008 Matryoshka Dolls Again largest independent subset

Source: Internet
Author: User

 

/*

 

 

 

Question:

 

When the length, width, and height of a doll are larger than the other, the small one can be put in and asked about

 

Minimum Number

 

 

 

Analysis:

 

Find the largest independent set, use the total number of dolls-the maximum match, and use two layers of loops to create a picture first. Every time the length, width, and height of a doll are larger than j hours,

 

Then g [I] [j] =
If it is true, you can create a graph. At the beginning, I first sorted it, and then I found that it was not needed... Direct

 

You can create a graph by repeating the two layers and then comparing them. Finding the maximum match is a pure hungy algorithm.

 

 

 

*/

 

# Include
<Iostream>

 

# Include
<Cstring>

 

# Include
<Cstdio>

 

Using namespace
Std;

 

# Define X 502

 

Int
Xm [X], ym [X], n, m;

 

Bool g [X] [X], use [X];

 

Struct node

 

{

 

Int a, B, c;

 

} P [X];

 

Bool dfs (int u)

 

{

 

For (int v = 1; v <= n; 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 ()

 

{

 

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

 

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

 

Int ret = 0;

 

For (int u = 1; u <= n; 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> n, n)

 

{

 

For (int I = 1; I <= n; I ++)

 

Scanf ("% d", & p [I]. a, & p [I]. B, & p [I]. c );

 

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

 

For (int I = 1; I <= n; I ++) // create a graph

 

For (int j = 1; j <= n; j ++)

 

If (I! = J & p [j]. a> p [I]. a & p [j]. b> p [I]. B & p [j]. c> p [I]. c) // when all three conditions are met

 

G [j] [I] = true;

 

Printf ("% d \ n", 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.