Given two groups of cards A and B, how many points can B have?
First, convert all the card strings into decimal numbers, and then use numbers as points,
The relationship between elements in A set and numbers in A set is edge, which is obviously A typical problem of minimum vertex overwrite.
[Csharp]
# Include "stdio. h"
# Include "string. h"
# Define N 52
Int map [N] [N], v [N], link [N];
Int A [N], B [N], t, n;
Int dfs (int k)
{
Int I;
For (I = 1; I <= n; I ++)
{
If (map [k] [I] &! V [I])
{
V [I] = 1;
If (link [I] = 0 | dfs (link [I])
{
Link [I] = k;
Return 1;
}
}
}
Return 0;
}
Int main ()
{
Char c, d, e;
Int I, j, vv, flag, ans;
Int ap, bp;
Scanf ("% d", & t );
While (t --)
{
Scanf ("% d", & n );
Getchar ();
Flag = 1;
Ap = bp = 0;
For (I = 0; I <2 * n; I ++)
{
Scanf ("% c", & c, & d, & e );
If (c> = '0' & c <= '9 ')
Vv = c-'0 ';
If (c = 'T') vv = 10;
If (c = 'J') vv = 11;
If (c = 'q') vv = 12;
If (c = 'k') vv = 13;
If (c = 'A') vv = 14;
Vv * = 100;
If (d = 'H') vv + = 4;
If (d = 's') vv + = 3;
If (d = 'D') vv + = 2;
If (d = 'C') vv + = 1;
If (flag)
A [++ ap] = vv;
Else
B [++ bp] = vv;
If (e = '\ n ')
Flag = 0;
}
Memset (map, 0, sizeof (map ));
For (I = 1; I <= n; I ++)
{
For (j = 1; j <= n; j ++)
{
If (A [I] <B [j])
Map [j] [I] = 1;
}
} Www.2cto.com
Memset (link, 0, sizeof (link ));
Ans = 0;
For (I = 1; I <= n; I ++)
{
Memset (v, 0, sizeof (v ));
If (dfs (I ))
Ans ++;
}
Printf ("% d \ n", ans );
}
Return 0;
}
Author: yyf572132811