#3314. Destroyer
Destroyer
Destroyer
题面翻译
描述
给你N*N个1*1的小正方形组成的大正方形,问你破坏哪些边可以使得这个大正方形不再拥有任何子正方形。初始的时候,它可能会自动缺少某些边.这些边的编号方式如下图所示
输入
第一行包含一个整数(),表示测试用例的数量。
每个测试用例的第一行包含一个整数(),表示机器人的数量。
每个测试用例的第二行包含个整数(),表示第个机器人所在行前面的机器人数量。
所有测试用例中的总和不超过。
输出
对于每个测试用例,如果存在与机器人报告一致的机器人排列,则输出YES
。否则,输出NO
。
你可以以任何大小写形式输出答案。例如,字符串yEs
、yes
、Yes
和YES
都将被识别为肯定的回答。
提示
在第三个测试用例中,第三个机器人声称它前面有两个机器人。在这种情况下,直接在它前面的机器人应该有一个机器人在前面。没有机器人声称有这种情况,因此没有有效的排列。
题目描述
John is a lead programmer on a destroyer belonging to the space navy of the Confederacy of Independent Operating Systems. One of his tasks is checking if the electronic brains of robots were damaged during battles.
A standard test is to order the robots to form one or several lines, in each line the robots should stand one after another. After that, each robot reports the number of robots standing in front of it in its line.
An example of robots' arrangement (the front of the lines is on the left). The robots report the numbers above.The -th robot reported number . Unfortunately, John does not know which line each robot stands in, and can't check the reported numbers. Please determine if it is possible to form the lines in such a way that all reported numbers are correct, or not.
输入格式
The first line contains a single integer ( ), denoting the number of test cases.
The first line in each test case contains a single integer ( ) — the number of robots.
The second line in each test case contains integers ( ), is equal to the number of robots in front of the -th robot in its line.
The sum of over all test cases won't exceed .
输出格式
For each test case, output "YES", if there exists a robot arrangement consistent with robots' reports. Otherwise, output "NO".
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
样例 #1
样例输入 #1
5
6
0 1 2 0 1 0
9
0 0 0 0 1 1 1 2 2
3
0 0 2
1
99
5
0 1 2 3 4
样例输出 #1
YES
YES
NO
NO
YES
提示
Example arrangement consistent with robot statements from the first example test case:
Example arrangement consistent with robot statements from the second example is shown in the statement.
In the third test case, the third robot claims that there are two machines in front of it. In such a case, the robot directly in front of it would have one machine in front. No robot claims that, so there is no valid arrangement.