Question Analysis: in fact, this question is the same as that on HDU. However, for each rectangle, you only need to put the rectangle consisting of length, width, width, and length into an array. This question is relatively simpler.
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
Typedef struct
{
Int w;
Int h;
} RECT;
RECT rect [2000];
Int dp [2000];
Int compare (const void * a, const void * B)
{
RECT * p1 = (RECT *);
RECT * p2 = (RECT *) B;
If (p1-> w = p2-> w)
Return p1-> h-p2-> h;
Else
Return p1-> w-p2-> w;
}
Int max (const int a, const int B)
{
Return a> B? A: B;
}
Int DP (int n)
{
Int I, j;
Dp [0] = 1;
Int ans = 1;
For (I = 1; I <n; ++ I)
{
Dp [I] = 1;
For (j = 0; j <I; ++ j)
{
If (rect [j]. w <rect [I]. w & rect [j]. h <rect [I]. h)
Dp [I] = max (dp [I], dp [j] + 1 );
}
Ans = max (ans, dp [I]);
}
Return ans;
}
Int main ()
{
Int t, n;
Int I, k;
Int ans;
Scanf ("% d", & t );
While (t --)
{
Scanf ("% d", & n );
For (I = 0, k = 0; I <n; ++ I, ++ k)
{
Scanf ("% d", & rect [k]. w, & rect [k]. h );
If (rect [k]. w! = Rect [k]. h)
{
Rect [k + 1]. w = rect [k]. h;
Rect [k + 1]. h = rect [k]. w;
++ K;
}
}
N = k;
Qsort (rect, n, sizeof (rect [0]), compare );
Ans = DP (n );
Printf ("% d \ n", ans );
}
}