It turns out that all D should be initialized to 1 during initialization;
Because the initialization result for each vertex is 1;
I didn't realize at the beginning ,,,
# Include <stdio. h> # include <string. h ># include <iostream> # include <string> # include <algorithm> # define max (a, B) (a)> (B )? (A): (B) using namespace STD; const int maxn = 1005; struct node {int A; int B;} Q [maxn]; int N; int d [maxn]; bool CMP (const node & A, const node & B) {if (. A = B. a) {return. B <B. b;} return. A <B. a;} void print () {for (INT I = 1; I <= N; I ++) {printf ("% d: X = % d y = % d \ n ", I, Q [I]. a, Q [I]. b) ;}} bool judge (int I, Int J) {If (Q [I]. a> q [J]. A & Q [I]. b> q [J]. b) {return true;} return false;} int main () {int t; I Nt a, B; scanf ("% d", & T); While (t --) {scanf ("% d", & N); For (INT I = 1; I <= N; I ++) {scanf ("% d", & A, & B); If (A> B) {swap (, b);} Q [I]. A = A; Q [I]. B = B;} Sort (q + 1, q + n + 1, CMP); // print (); int T = 1; for (INT I = 1; I <maxn; I ++) {d [I] = 1 ;}for (INT I = 2; I <= N; I ++) {for (Int J = I-1; j> 0; j --) {If (Judge (I, j) {d [I] = max (d [I], d [J] + 1) ;}} T = max (T, d [I]);} printf ("% d \ n", T );} system ("pause"); Re Turn 0;}/* fuck !!! At the beginning, we need to initialize the D array under the crash =. = # all collapsed .*/