Question: Give 2 k points on the plane, and pair them one by one. Ask how many pairing Methods There are to keep moving from a certain point to the right in the loop (k <= 6)
Idea: Because K is very small, the matching method is violent enumeration, and then ring judgment, when ring judgment, you need to pay attention to the four points 1, 2, 3, 1 and 3 on a straight line, pairing 2 and 4, you can find that it does not constitute a ring. For details, see the code.
/*{
ID: a4298442
Prob: Wormhole
Lang: C ++
}
*/
# Include <stdio. h>
# Include <iostream>
# Include <fstream>
# Include <string. h>
# Include <algorithm>
# Define maxn1000
Using namespace STD;
Ifstream fin ("wormhole. In ");
Ofstream fout ("wormhole. Out ");
Struct t {int X; int y;} p [maxn];
Int ans = 0, G [maxn], Match [maxn], n, visit [maxn];
Int CMP (t x, t y ){
Return (x. y <Y. Y | (x. y = Y. Y) & (x. x <Y. X )));
}
Int circle (int u)
{
Int vis [100] = {0}, V = G [u];
Vis [u] = 1;
While (V! = 0 ){
U = match [v];
If (! U) return 0; V = G [u];
If (vis [u]) return 1; vis [u] = 1;
}
Return 0;
}
Void DFS (int K, int U, int num ){
If (num = N ){
For (INT I = 1; I <= N; I ++) if (Circle (I) {ans ++; break ;}
Return;
}
Visit [k] = 1;
For (INT I = (u = 0 )? K + 1:1; I <= N; I ++) if (visit [I] = 0 ){
If (u = 0) {G [I] = K; G [k] = I ;}
DFS (I, u ^ 1, num + 1 );
If (u = 0) g [I] = G [k] = 0; else break;
}
Visit [k] = 0;
}
Int main (){
Fin> N;
For (INT I = 1; I <= N; I ++) Fin> P [I]. x> P [I]. Y;
Sort (p + 1, p + 1 + N, CMP );
For (INT I = 2; I <= N; I ++) if (P [I]. Y = P [I-1]. Y) Match [I-1] = I;
DFS (1, 0, 1 );
Fout <ans <Endl;
Return 0;
}
[Usaco] wormholes [brute force]