A13733 | Yet Another Segments Subset
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given $n$ segments on a coordinate axis $OX$ . The $i$ -th segment has borders $[l_i; r_i]$ . All points $x$ , for which $l_i \le x \le r_i$ 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 $[l_i; r_i]$ and $[l_j; r_j]$ 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 $[l_i; r_i]$ lies inside the segment $[l_j; r_j]$ if $l_j \le l_i$ and $r_i \le r_j$ . 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.
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 $[l_i; r_i]$ and $[l_j; r_j]$ 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 $[l_i; r_i]$ lies inside the segment $[l_j; r_j]$ if $l_j \le l_i$ and $r_i \le r_j$ . 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.
输入格式
The first line of the input contains one integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ( $1 \le n \le 3000$ ) — the number of segments. The next $n$ lines describe segments. The $i$ -th segment is given as two integers $l_i$ and $r_i$ ( $1 \le l_i \le r_i \le 2 \cdot 10^5$ ), where $l_i$ is the left border of the $i$ -th segment and $r_i$ 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$ ( $\sum n \le 3000$ ).
The first line of the test case contains one integer $n$ ( $1 \le n \le 3000$ ) — the number of segments. The next $n$ lines describe segments. The $i$ -th segment is given as two integers $l_i$ and $r_i$ ( $1 \le l_i \le r_i \le 2 \cdot 10^5$ ), where $l_i$ is the left border of the $i$ -th segment and $r_i$ 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$ ( $\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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted