HDU 3395 special fish (Bipartite Graph)

Source: Internet
Author: User

It seems a little pitfall. I open the array to 1010, and the result times out. I changed it to 101! Bored !!!

"XOR" appears in the question. I didn't understand it when I read the question. Later, Baidu gave me an explanation of "different or ~~~~

A simple binary chart !!!

Here is an overview from Baidu:

/*

Definition:

Exclusive or (exclusive or operation, modulo 2 and) exclusive or (XOR) is a mathematical operator. It is applied to logical operations. The XOR symbol is "^ ". The algorithm is a ^ B = (a' and B) or (A and B ') (a' Is Not ). A ^ B = a' B + AB '(a' is a's inverse) (B' is B's inverse ). True or false results are true, false or true results are true, true or false results are false, and false results are false. That is to say, if two values are different, they are different or the result is true. Otherwise, it is false. The difference is 1, and the same is 0. an exclusive or semi-addition operation is equivalent to a binary addition that does not bring in bits. In a binary system, 1 indicates the truth, 0 indicates false, and then the exclusive or operation is as follows: 0 or 0 = 0, 1, or 0 = 1, 0, or 1 = 1, 1 = 0 (0, 1). These rules are the same as addition, only do not bring in bits. There are three kinds of calculus in the XOR, EOR, and ex-or programs: XOR, XOR, and ^. The usage is as follows: z = x ^ y; Z = x XOR y; Algorithm:

1. A ^ A = 02. A ^ B = B ^ A3. a ^ B ^ c = a ^ (B ^ c) = (a ^ B) ^ C; 4. D = a ^ B ^ C can introduce a = d ^ B ^ C.5. a ^ B ^ A = B .6. if X is a binary number of 0101, if y is a binary number of 1011, then x ^ y = 1110 only returns 1 if the two comparison bits are different. Otherwise, the result is 0, that is, "Same as 0, different as 1 "!
Input Operator Input Result
1 ^ 0 1
1 ^ 1 0
0 ^ 0 0
0 ^ 1 1

*/

# Include <stdio. h>

# Include <string. h>

# Define max (A, B) A> B? A: B
# Define min (a, B) a <B? A: B
# Define INF 100000000
# Define n 101

Int map [N] [N], LX [N], Ly [N], Match [N], SX [N], Sy [N];
Int N;

Int find (int K)
{
Int I;
SX [k] = 1;
For (I = 1; I <= N; I ++)
{
If (Map [k] [I] = Lx [k] + ly [I] & Sy [I] = 0)
{
Sy [I] = 1;
If (Match [I] = 0 | find (Match [I]) = 1)
{
Match [I] = K;
Return 1;
}
}
}
Return 0;
}

Int km ()
{
Int I, J, K, ANS = 0;
Memset (match, 0, sizeof (MATCH ));
Memset (LX, 0, sizeof (LX ));
Memset (ly, 0, sizeof (ly ));
For (I = 1; I <= N; I ++)
For (j = 1; j <= N; j ++)
Lx [I] = max (LX [I], map [I] [J]);
For (I = 1; I <= N; I ++)
{
While (1)
{
Memset (sx, 0, sizeof (SX ));
Memset (SY, 0, sizeof (SY ));
If (find (I) break;
Else
{
Int A = inf;
For (j = 1; j <= N; j ++)
If (SX [J])
For (k = 1; k <= N; k ++)
If (! Sy [k])
A = min (A, LX [J] + ly [k]-map [J] [k]);
For (j = 1; j <= N; j ++)
{
If (SX [J]) lx [J]-=;
If (SY [J]) ly [J] + =;
}
}
}
}
For (I = 1; I <= N; I ++)
{
Ans + = map [Match [I] [I];
}
Return ans;
}

Int main ()
{
Int I, j, B [200];
Char AA [1, 200] [2, 200];
While (scanf ("% d", & N), n)
{
Memset (MAP, 0, sizeof (MAP ));
For (I = 1; I <= N; I ++)
Scanf ("% d", & B [I]);
For (I = 1; I <= N; I ++)
{
Scanf ("% s", AA [I] + 1 );
For (j = 1; j <= N; j ++)
If (AA [I] [J] = '1 ')
{
Map [I] [J] = B [I] ^ B [J];
}
}
Printf ("% d \ n", km ());
}
Return 0;
}
/*
# Include <stdio. h>
Int main ()
{
Int I, J;
For (I = 1; I <= 10; I ++)
{
For (j = 1; j <= 10; j ++)
Printf ("% d", I ^ J );

Printf ("\ n ");
}

Return 0;

}*/

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

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.