[Longest non-ascending subsequence + nlog (n)] Peking University POJ 3636 Nested Dolls

Source: Internet
Author: User

[Cpp]
/* The program is made by pyy */
/*----------------------------------------------------------------------------//
Copyright (c) 2012 panyanyany All rights reserved.
 
URL: http://poj.org/problem? Id = 3636
Name: 3636 Nested Dolls-longest non-ascending subsequence
 
Date: Monday, July 9, 2012
Time Stage: two hours
 
Result:
10404790 panyanyany
3636
Accepted 400 K 157 ms c ++
1827B 11:01:39
 
Test Data:
 
Review
Www.2cto.com
//----------------------------------------------------------------------------*/
 
# 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 maxn20009
 
# 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;
}
 
Int order [MAXN];
NODE a [MAXN];
 
Int LNotIncS (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)
{
R = len;
L = 1;
While (l <= r)
{
M = (l + r)> 1;
If (order [m]> = a [I]. h)
{
L = m + 1;
}
Else
R = m-1;
}
 
// The length of the updated ordered table is the maximum value of L.
// If the ordered table is ascending, the minimum value is updated.
If (order [l] <a [I]. h)
Order [l] = a [I]. h;
Len = max (len, l );
}
 
Return len;
}
 
Int main ()
{
Int I, tcase, n;
While (scanf ("% d", & tcase )! = EOF)
{
While (tcase --)
{
Scanf ("% d", & n );
For (I = 0; I <n; ++ I)
{
Scanf ("% d", & a [I]. w, & a [I]. h );
}
Printf ("% d \ n", LNotIncS (a, n ));
}
}
Return 0;
}
Author: panyanyany

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.