Rectangular nesting time limit: 3000 MS | memory limit: 65535 KB difficulty: 4 description There are n rectangles, each rectangle can be described with a, B, length and width. Rectangle X (a, B) can be nested in Rectangle Y (c, d) When and only when a <c, B <d or B <c, a <d (equivalent to rotating x 90 degrees ). For example, () can be nested in (), but cannot be nested in. Your task is to select as many rectangles as possible and arrange them in one row so that, except the last one, each rectangle can be nested in the next rectangle. The first line of the input is a positive number N (0 <N <10), indicating the number of test data groups. The first line of each group of test data is a positive number n, indicates the number of rectangles in the group of test data (n <= 1000) followed by n rows. Each row has two numbers a and B (0 <a, B <100 ), indicates the length and width of the rectangle. Each group of test data outputs a number, indicating the maximum number of rectangles that meet the conditions, sample input 1101 22 45 86 107 93 15 812 72 2 sample output 5 source classic question [cpp]/********** * ************************ Date: 2013-3-26 * Author: SJF0115 * question: Question 16: rectangular nesting * Source: http://acm.nyist.net/JudgeOnline/problem.php? Pid = 16 * result: AC * Source: Nanyang Institute of Technology OJ * Summary: * *********************************/# include <stdio. h> # include <string. h> # include <stdlib. h> typedef struct Rec {int MaxL; int MinL;} Rec; int cmp (const void * a, const void * B) {struct Rec * c = (Rec *); struct Rec * d = (Rec *) B; return c-> MaxL-d-> MaxL;} int main () {int N, M, a, B, I, j; Rec rec [1010]; int dp [1010]; // freopen ("C: \ Users \ SJF \ Desktop \ acm.txt", "r", std In); scanf ("% d", & N); while (N --) {scanf ("% d", & M); // initialize for (I = 0; I <M; I ++) {scanf ("% d", & a, & B); if (a <B) {rec [I]. maxL = B; rec [I]. minL = a;} else {rec [I]. maxL = a; rec [I]. minL = B ;}/// sort by maximum edge qsort (rec, M, sizeof (rec [0]), cmp); // initialize the array dp memset (dp, 0, sizeof (dp); for (I = 0; I <M; I ++) {dp [I] = 1; for (j = 0; j <I; j ++) {if (rec [I]. maxL> rec [j]. maxL & rec [I]. minL> rec [j]. minL) {if (dp [I] <dp [j] + 1) {dp [I] = dp [j] + 1 ;}}// output int Max = 0; for (I = 0; I <M; I ++) {if (dp [I]> Max) {Max = dp [I] ;}} printf ("% d \ n", Max );} return 0 ;} /********************************** Date: 2013-3-26 * Author: SJF0115 * question: Question 16: rectangular nesting * Source: http://acm.nyist.net/JudgeOnline/problem.php? Pid = 16 * result: AC * Source: Nanyang Institute of Technology OJ * Summary: * *********************************/# include <stdio. h> # include <string. h> # include <stdlib. h> typedef struct Rec {int MaxL; int MinL;} Rec; int cmp (const void * a, const void * B) {struct Rec * c = (Rec *); struct Rec * d = (Rec *) B; return c-> MaxL-d-> MaxL;} int main () {int N, M, a, B, I, j; Rec rec [1010]; int dp [1010]; // freopen ("C: \ Users \ SJF \ Desktop \ acm.txt", "r ", stdin); scanf ("% d", & N); while (N --) {scanf ("% d", & M); // initialize for (I = 0; I <M; I ++) {scanf ("% d", & a, & B); if (a <B) {rec [I]. maxL = B; rec [I]. minL = a;} else {rec [I]. maxL = a; rec [I]. minL = B ;}/// sort by maximum edge qsort (rec, M, sizeof (rec [0]), cmp); // initialize the array dpmemset (dp, 0, sizeof (dp); for (I = 0; I <M; I ++) {dp [I] = 1; for (j = 0; j <I; j ++) {if (rec [I]. maxL> rec [j]. maxL & rec [I]. minL> rec [j]. minL) {if (dp [I] <dp [j] + 1) {dp [I] = dp [j] + 1 ;}}}} // output int Max = 0; for (I = 0; I <M; I ++) {if (dp [I]> Max) {Max = dp [I] ;}} printf ("% d \ n", Max) ;}return 0 ;}