Title Link: http://acm.nyist.net/JudgeOnline/problem.php?pid=16
Set up the rectangle like a baby. First, the rectangle is sorted from small to large, then the longest ascending subsequence is done.
1 /*2 ━━━━━┒ギリギリ♂eye! 3 ┓┏┓┏┓┃キリキリ♂mind! 4 ┛┗┛┗┛┃\0/5 ┓┏┓┏┓┃/6 ┛┗┛┗┛┃ノ)7 ┓┏┓┏┓┃8 ┛┗┛┗┛┃9 ┓┏┓┏┓┃Ten ┛┗┛┗┛┃ One ┓┏┓┏┓┃ A ┛┗┛┗┛┃ - ┓┏┓┏┓┃ - ┃┃┃┃┃┃ the ┻┻┻┻┻┻ - */ -#include <algorithm> -#include <iostream> +#include <iomanip> -#include <cstring> +#include <climits> A#include <complex> at#include <fstream> -#include <cassert> -#include <cstdio> -#include <bitset> -#include <vector> -#include <deque> in#include <queue> -#include <stack> to#include <ctime> +#include <Set> -#include <map> the#include <cmath> * using namespacestd; $ #defineFr FirstPanax Notoginseng #defineSC Second - #defineCL Clear the #defineBUG puts ("Here!!!") + #defineW (a) while (a--) A #definePB (a) push_back (a) the #defineRint (a) scanf ("%d", &a) + #defineRll (a) scanf ("%i64d", &a) - #defineRs (a) scanf ("%s", a) $ #defineCIN (a) CIN >> a $ #defineFRead () freopen ("in", "R", stdin) - #defineFWrite () freopen ("Out", "w", stdout) - #defineRep (i, Len) for (LL i = 0; i < (len); i++) the #defineFor (I, A, Len) for (LL i = (a); I < (len); i++) - #defineCls (a) memset ((a), 0, sizeof (a))Wuyi #defineCLR (A, X) memset ((a), (x), sizeof (a)) the #defineFuint (a) memset ((a), 0x7f7f, sizeof (a)) - #defineLRT RT << 1 Wu #defineRRT RT << 1 | 1 - #definePi 3.14159265359 About #defineRT return $ #defineLowbit (x) x & (-X) - #defineOnenum (x) __builtin_popcount (x) -typedefLong LongLL; -typedefLong DoubleLD; Atypedef unsignedLong LongUint; +typedef PAIR<LL, Ll>PII; thetypedef pair<string, ll>psi; -typedef map<string, ll>MSI; $typedef vector<ll>VI; thetypedef vector<ll>VL; thetypedef vector<vl>VVL; thetypedef vector<BOOL>vb; the -typedefstructSquare { in intx, y; the Square () {} theSquare (intXxintyy): X (xx), Y (yy) {} About }square; the the Const intMAXN =1010; the Square S[MAXN]; + intN; - intDP[MAXN]; the Bayi BOOLCMP (square A, square b) { the if(a.x = = b.x)returnA.Y <=b.y; the returnA.x <b.x; - } - the BOOLOK (square A, square b) { the returna.x > b.x && a.y >b.y; the } the - intMain () { the //FRead (); the intT, x, y; the Rint (T);94 W (T) { the Cls (DP); the Rint (n); thefor (I,1, n+1) {98 Rint (x); Rint (y); About if(X >y) Swap (x, y); -S[i] =Square (x, y);101 }102Sort (s+1, s+n+1, CMP);103 intRET =0;104for (I,2, n+1) { theDp[i] =0;106For (J,1, i+1) {107 if(OK (s[i], s[j])) {108Dp[i] = max (Dp[i], dp[j]+1);109 } the }111RET =Max (Dp[i], ret); the }113printf"%d\n", ret+1); the } theRt0; the}
[NYIST16] Rectangle nesting (DP, longest ascending subsequence)