As long as the maximum value in the 1~x is found, then the segment tree is easily mle, so it can be used in a tree-like array.
#include <cstdio> #include <cstring> #include <algorithm> #include <map> #include <set># Include <bitset> #include <queue> #include <stack> #include <string> #include <iostream># Include <cmath> #include <climits>using namespace std;const int maxn = 1005;class BIT {int VAL[MAXN << 2] , N;inline int lowbit (int x) {return x & (-X);} Public:void init (int __n) {n = __n;memset (val, 0, sizeof (val));} void ADDV (int pos, int v) {while (pos <= n) {Val[pos] = max (Val[pos], v);p OS + = Lowbit (pos);}} int getmax (int pos) {int ret = 0;while (pos >= 1) {ret = max (ret, val[pos]);p os-= Lowbit (POS);} return ret;}}; BIT Bit[maxn];int A[MAXN], B[MAXN], F[maxn][maxn][2];int N, M, NUM[MAXN << 2], numcnt;inline int GetID (int Val) {RET Urn lower_bound (num, num + numcnt, Val)-num + 1;} int main () {int T; scanf ("%d", &t), for (int kase = 1; kase <= T; kase++) {memset (f, 0, sizeof (f)); scanf ("%d%d", & n, &m); numcnt = 0;for (inti = 1; I <= N; i++) {scanf ("%d%d", &a[i], &b[i]); num[numcnt++] = a[i];num[numcnt++] = B[i];} Sort (num, num + numcnt), numcnt = unique (num, num + numcnt)-num;for (int i = 1; I <= n; i++) {A[i] = GetID (A[i]); B[i] = GetID (B[i]);} for (int i = 0; I <= m; i++) Bit[i].init (numcnt), int ans = 0;for (int i = 1; I <= n; i++) {for (int j = m; j >= 0;- -J) {int prev_max = Bit[j]. Getmax (A[i]-1); F[i][j][0] = Prev_max + 1;BIT[J].ADDV (A[i], f[i][j][0]); ans = max (ans, f[i][j][0]); if (j = = 0) continue;pr Ev_max = Bit[j-1]. Getmax (B[i]-1); f[i][j][1] = Prev_max + 1;BIT[J].ADDV (B[i], f[i][j][1]); ans = max (ans, f[i][j][1]);}} printf ("%d\n", ans);} return 0;}
HDU 5125 Magic Ball dp+ Tree Array