[Cpp]
/* The program is made by pyy */
/*----------------------------------------------------------------------------//
Copyright (c) 2012 panyanyany All rights reserved.
URL: http://poj.org/problem? Id = 1065
Name: 1065 Wooden Sticks
Date: Monday, July 9, 2012
Time Stage: one hour
Result:
10405687 panyanyany
1065
Accepted 248 K 16 ms c ++
1730B 12:30:02
Test Data:
Review:
It is similar to POJ 3636, except that h and w columns are sorted in ascending order. Then, find the descent sub-sequence for one of the columns.
//----------------------------------------------------------------------------*/
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <math. h>
# Include <vector>
# Include <algorithm>
# Include <iostream>
# Include <queue>
# Include <set>
# Include <string>
Using namespace std;
# Define MEM (a, v) memset (a, v, sizeof (a) // a for address, v for value
# Define max (x, y) (x)> (y )? (X): (y ))
# Define min (x, y) (x) <(y )? (X): (y ))
# Define INF (0x3f3f3f)
# Define maxn10009
# Define L (x) <1)
# Define R (x) <1) | 1)
# Define M (x, y) (x) + (y)> 1)
# Define DB //
Struct NODE {
Int w, h;
};
Bool cmp (const NODE & lhs, const NODE & rhs)
{
If (lhs. w = rhs. w)
Return lhs. h <rhs. h;
Return lhs. w <rhs. w;
}
NODE a [MAXN];
Int order [MAXN];
Int LDesS (NODE a [], int n)
{
Int I, r, l, len, m;
MEM (order, 0 );
Sort (a, a + n, cmp );
Len = 1;
For (I = 0; I <n; ++ I)
{
L = 1;
R = len;
While (l <= r)
{
M = (l + r)> 1;
If (order [m]> a [I]. h)
L = m + 1;
Else
R = m-1;
}
If (order [l] <a [I]. h)
Order [l] = a [I]. h;
Len = max (len, l );
}
Return len;
}
Int main () www.2cto.com
{
Int I, tc, n;
While (scanf ("% d", & tc )! = EOF)
{
While (tc --)
{
Scanf ("% d", & n );
For (I = 0; I <n; ++ I)
Scanf ("% d", & a [I]. w, & a [I]. h );
Printf ("% d \ n", LDesS (a, n ));
}
}
Return 0;
}
Author: panyanyany