CF1399F.Yet Another Segments Subset

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn segments on a coordinate axis OXOX . The ii -th segment has borders [li;ri][l_i; r_i] . All points xx , for which lixril_i \le x \le r_i holds, belong to the ii -th segment.

Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.

Two segments [li;ri][l_i; r_i] and [lj;rj][l_j; r_j] are non-intersecting if they have no common points. For example, segments [1;2][1; 2] and [3;4][3; 4] , [1;3][1; 3] and [5;5][5; 5] are non-intersecting, while segments [1;2][1; 2] and [2;3][2; 3] , [1;2][1; 2] and [2;2][2; 2] are intersecting.

The segment [li;ri][l_i; r_i] lies inside the segment [lj;rj][l_j; r_j] if ljlil_j \le l_i and rirjr_i \le r_j . For example, segments [2;2][2; 2] , [2,3][2, 3] , [3;4][3; 4] and [2;4][2; 4] lie inside the segment [2;4][2; 4] , while [2;5][2; 5] and [1;4][1; 4] are not.

You have to answer tt independent test cases.

输入格式

The first line of the input contains one integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases. Then tt test cases follow.

The first line of the test case contains one integer nn ( 1n30001 \le n \le 3000 ) — the number of segments. The next nn lines describe segments. The ii -th segment is given as two integers lil_i and rir_i ( 1liri21051 \le l_i \le r_i \le 2 \cdot 10^5 ), where lil_i is the left border of the ii -th segment and rir_i is the right border of the ii -th segment.

Additional constraint on the input: there are no duplicates in the list of segments.

It is guaranteed that the sum of nn does not exceed 30003000 ( n3000\sum n \le 3000 ).

输出格式

For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.

输入输出样例

  • 输入#1

    4
    4
    1 5
    2 4
    2 3
    3 4
    5
    1 5
    2 3
    2 5
    3 5
    2 2
    3
    1 3
    2 4
    2 3
    7
    1 10
    2 8
    2 5
    3 4
    4 4
    6 8
    7 7

    输出#1

    3
    4
    2
    7
首页