CF1881E.Block Sequence
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given a sequence of integers a of length n.
A sequence is called beautiful if it has the form of a series of blocks, each starting with its length, i.e., first comes the length of the block, and then its elements. For example, the sequences [3, 3, 4, 5, 2, 6, 1] and [1, 8, 4, 5, 2, 6, 1] are beautiful (different blocks are colored differently), while [1], [1, 4, 3], [3, 2, 1] are not.
In one operation, you can remove any element from the sequence. What is the minimum number of operations required to make the given sequence beautiful?
给定一个长度为 n 的整数序列 a。
若一个序列可表示为若干个“块”拼接而成,且每个块均以其自身长度开头(即:每个块首先出现的是该块的长度,随后是该块的所有元素),则称该序列为“优美的”。例如,序列 [3, 3, 4, 5, 2, 6, 1] 和 [1, 8, 4, 5, 2, 6, 1] 是优美的(不同块以不同颜色标出),而 [1]、[1, 4, 3]、[3, 2, 1] 则不是。
每次操作中,你可以从序列中删除任意一个元素。问:使给定序列变为优美序列所需的最少操作次数是多少?
输入格式
The first line of the input contains a single integer t (1≤t≤104) — the number of test cases. Then follows the descriptions of the test cases.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of the sequence a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤106) — the elements of the sequence a.
It is guaranteed that the sum of the values of n over all test cases does not exceed 2⋅105.
输入的第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105),表示序列 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤106),表示序列 a 的元素。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output a single number — the minimum number of deletions required to make the sequence a beautiful.
对于每个测试用例,输出一个整数——使序列 a 变为“优美”的最少删除次数。
输入输出样例
输入#1
7 7 3 3 4 5 2 6 1 4 5 6 3 2 6 3 4 1 6 7 7 3 1 4 3 5 1 2 3 4 5 5 1 2 3 1 2 5 4 5 5 1 5
输出#1
0 4 1 1 2 1 0
说明/提示
In the first test case of the example, the given sequence is already beautiful, as shown in the statement.
In the second test case of the example, the sequence can only be made beautiful by removing all elements from it.
In the fifth test case of the example, the sequence can be made beautiful by removing the first and last elements. Then the sequence will become [2, 3, 4].
在示例的第一个测试用例中,给定序列本身已是优美的,如题面所述。
在示例的第二个测试用例中,该序列只能通过移除其中所有元素才能变得优美。
在示例的第五个测试用例中,该序列可通过移除第一个和最后一个元素而变得优美。此时序列将变为 [2, 3, 4]。
输入解题思路,AI测评打分。不知道怎么写?