A9186 | Sereja and Sets
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Sereja has $m$ non-empty sets of integers $A_{1},A_{2},...,A_{m}$ . What a lucky coincidence! The given sets are a partition of the set of all integers from 1 to $n$ . In other words, for any integer $v$ $(1<=v<=n)$ there is exactly one set $A_{t}$ such that . Also Sereja has integer $d$ .
Sereja decided to choose some sets from the sets he has. Let's suppose that $i_{1},i_{2},...,i_{k}$ $(1<=i_{1}<i_{2}<...<i_{k}<=m)$ are indexes of the chosen sets. Then let's define an array of integers $b$ , sorted in ascending order, as a union of the chosen sets, that is, . We'll represent the element with number $j$ in this array (in ascending order) as $b_{j}$ . Sereja considers his choice of sets correct, if the following conditions are met:
$b_{1}<=d; b_{i+1}-b_{i}<=d (1<=i<|b|); n-d+1<=b_{|b|}.$ Sereja wants to know what is the minimum number of sets $(k)$ that he can choose so that his choice will be correct. Help him with that.
Sereja decided to choose some sets from the sets he has. Let's suppose that $i_{1},i_{2},...,i_{k}$ $(1<=i_{1}<i_{2}<...<i_{k}<=m)$ are indexes of the chosen sets. Then let's define an array of integers $b$ , sorted in ascending order, as a union of the chosen sets, that is, . We'll represent the element with number $j$ in this array (in ascending order) as $b_{j}$ . Sereja considers his choice of sets correct, if the following conditions are met:
$b_{1}<=d; b_{i+1}-b_{i}<=d (1<=i<|b|); n-d+1<=b_{|b|}.$ Sereja wants to know what is the minimum number of sets $(k)$ that he can choose so that his choice will be correct. Help him with that.
输入格式
The first line contains integers $n$ , $m$ , $d$ $(1<=d<=n<=10^{5},1<=m<=20)$ . The next $m$ lines contain sets. The first number in the $i$ -th line is $s_{i}$ $(1<=s_{i}<=n)$ . This number denotes the size of the $i$ -th set. Then the line contains $s_{i}$ distinct integers from 1 to $n$ — set $A_{i}$ .
It is guaranteed that the sets form partition of all integers from 1 to $n$ .
It is guaranteed that the sets form partition of all integers from 1 to $n$ .
输出格式
In a single line print the answer to the problem — the minimum value $k$ at the right choice.
输入输出样例
输入 #1
3 2 2 1 2 2 1 3
输出 #1
1
输入 #2
5 1 1 5 4 5 3 2 1
输出 #2
1
输入 #3
7 3 1 4 1 3 5 7 2 2 6 1 4
输出 #3
3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted