CF1399F.Yet Another Segments Subset
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n segments on a coordinate axis OX. The i-th segment has borders [li;ri]. All points x, for which li≤x≤ri holds, belong to the i-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] and [lj;rj] are non-intersecting if they have no common points. For example, segments [1;2] and [3;4], [1;3] and [5;5] are non-intersecting, while segments [1;2] and [2;3], [1;2] and [2;2] are intersecting.
The segment [li;ri] lies inside the segment [lj;rj] if lj≤li and ri≤rj. For example, segments [2;2], [2,3], [3;4] and [2;4] lie inside the segment [2;4], while [2;5] and [1;4] are not.
You have to answer t independent test cases.
给你 n 条位于坐标轴 OX 上的线段。第 i 条线段的端点为 [li;ri]。所有满足 li≤x≤ri 的点 x 均属于第 i 条线段。
你的任务是从给定的线段集合中选出一个最大(包含线段数量最多)的子集,使得该子集中任意两条线段要么互不相交,要么其中一条完全位于另一条内部。
两条线段 [li;ri] 和 [lj;rj] 互不相交,当且仅当它们没有公共点。例如,线段 [1;2] 与 [3;4]、[1;3] 与 [5;5] 是互不相交的;而线段 [1;2] 与 [2;3]、[1;2] 与 [2;2] 是相交的。
线段 [li;ri] 位于线段 [lj;rj] 内部,当且仅当 lj≤li 且 ri≤rj。例如,线段 [2;2]、[2;3]、[3;4] 和 [2;4] 均位于线段 [2;4] 内部;而 [2;5] 和 [1;4] 不在 [2;4] 内部。
你需要处理 t 个相互独立的测试用例。
输入格式
The first line of the input contains one integer t (1≤t≤1000) — the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1≤n≤3000) — the number of segments. The next n lines describe segments. The i-th segment is given as two integers li and ri (1≤li≤ri≤2⋅105), where li is the left border of the i-th segment and ri is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (∑n≤3000).
输入的第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤3000),表示线段的数量。接下来的 n 行描述这些线段。第 i 个线段由两个整数 li 和 ri(1≤li≤ri≤2⋅105)给出,其中 li 是第 i 个线段的左端点,ri 是第 i 个线段的右端点。
输入的额外约束:线段列表中不存在重复线段。
保证所有测试用例中 n 的总和不超过 3000(即 ∑n≤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
输入解题思路,AI测评打分。不知道怎么写?