HDU (3395) special fish

Source: Internet
Author: User

KM bare question

Each fish considers itself as a male and will attack the fish that it considers as a female. Each fish can only be attacked once, after being attacked, it will generate eggs (the number is the exclusive or operation of the value of the catfish)

The meaning of this question is not easy to understand ..

# Include <string. h>
# Include <stdio. h>
# Define n 110
# Define INF 0x3fffffff
Int map [N] [N], LX [N], Ly [N], SX [N], Sy [N], n, d [N], cont [N], Match [N];
Int find (int x)
{
SX [x] = 1;
For (INT I = 0; I <n; I ++)
{
If (SY [I] = 1) continue;
Int temp = Lx [x] + ly [I]-map [x] [I];
If (temp = 0)
{
Sy [I] = 1;
If (Match [I] =-1 | find (Match [I]) = 1)
{
Match [I] = X;
Return 1;
}
}
Else d [I] = d [I]> temp? Temp: d [I];
}
Return 0;
}
Int km ()
{
Int I, J, K, sum, min;
Memset (match,-1, sizeof (MATCH ));
Memset (ly, 0, sizeof (ly ));
For (I = 0; I <n; I ++)
{
Lx [I] = map [I] [0];
For (j = 1; j <n; j ++)
If (LX [I] <map [I] [J])
Lx [I] = map [I] [J];
}
For (I = 0; I <n; I ++)
{
For (j = 0; j <n; j ++)
D [J] = inf;
While (1)
{
Memset (sx, 0, sizeof (SX ));
Memset (SY, 0, sizeof (SY ));
If (find (I) = 1) break;
Min = inf;
For (k = 0; k <n; k ++)
If (SY [k] = 0 & min> d [k])
Min = d [k];
For (j = 0; j <n; j ++)
{
If (SX [J] = 1) lx [J]-= min;
If (SY [J] = 1) ly [J] + = min;
}
}
}
Sum = 0;
For (I = 0; I <n; I ++)
Sum + = map [Match [I] [I];
Return sum;
}
Int main ()
{
Int I, J, K;
Char STR [110];
While (scanf ("% d", & N )! =-1 & N)
{
For (I = 0; I <n; I ++)
Scanf ("% d", & Cont [I]);
Memset (MAP, 0, sizeof (MAP ));
For (I = 0; I <n; I ++)
{
Scanf ("% s", STR );
For (j = 0; j <n; j ++)
If (STR [J] = '1 ')
Map [I] [J] = cont [I] ^ cont [J];
}
K = km ();
Printf ("% d \ n", k );
}
Return 0;
}

 

 

# Include "stdio. H"
# Include "string. H"
# Define INF 999999
Int SX [110], Sy [110];
Int lx [110], Ly [110];
Int map [110] [110];
Int n, m, link [110];
Int A [1000];
Int find (int K)
{
Int I;
SX [k] = 1;
For (I = 1; I <= m; I ++)
{
If (SY [I] = 0 & lx [k] + ly [I] = map [k] [I])
{
Sy [I] = 1;
If (link [I] =-1 | find (link [I])
{
Link [I] = K;
Return 1;
}
}
}
Return 0;
}
Int km ()
{
Int I, J, K,;
Memset (LX, 0, sizeof (LX ));
Memset (ly, 0, sizeof (ly ));
For (I = 1; I <= m; I ++)
For (j = 1; j <= m; j ++)
If (LX [I] <map [I] [J])
Lx [I] = map [I] [J];
For (I = 1; I <= m; I ++)
{
While (1)
{
A = inf;
Memset (sx, 0, sizeof (SX ));
Memset (SY, 0, sizeof (SY ));
If (find (I ))
Break;
For (j = 1; j <= m; j ++)
{
If (SX [J])
For (k = 1; k <= m; k ++)
If (! Sy [k])
If (A> lx [J] + ly [k]-map [J] [k])
A = Lx [J] + ly [k]-map [J] [k];
}
For (j = 1; j <= m; j ++)
{
If (SX [J])
Lx [J]-=;
If (SY [J])
Ly [J] + =;
}
}
}
Int sum = 0;
For (I = 1; I <= m; I ++)
{
Sum + = map [LINK [I] [I];
}
Return sum;
}
Int main ()
{
Int I, J, K;
Char B [100];
While (scanf ("% d", & M), m)
{
For (I = 1; I <= m; I ++)
Scanf ("% d", & A [I]);
Memset (MAP, 0, sizeof (MAP ));
Memset (link,-1, sizeof (Link ));
For (I = 1; I <= m; I ++)
{
Scanf ("% s", B + 1 );
For (j = 1; j <= m; j ++)
If (B [J] = '1 ')
Map [I] [J] = A [I] ^ A [J];
}
K = km ();
Printf ("% d \ n", k );
}
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.