#DP1050. Sending a Sequence Over the Network
Sending a Sequence Over the Network
描述
The sequence is sent over the network as follows:
1.sequence is split into segments (each element of the sequence belongs to exactly one segment, each segment is a group of consecutive elements of sequence); 2.for each segment, its length is written next to it, either to the left of it or to the right of it; 3.the resulting sequence is sent over the network.
For example, we needed to send the sequence . Suppose it was split into segments as follows: $[\color{red}{1}] + [\color{blue}{2, 3, 1}] + [\color{green}{2, 3}]$. Then we could have the following sequences:
•$b = [1, \color{red}{1}, 3, \color{blue}{2, 3, 1}, \color{green}{2, 3}, 2]$,
•$b = [\color{red}{1}, 1, 3, \color{blue}{2, 3, 1}, 2, \color{green}{2, 3}]$,
•$b = [\color{red}{1}, 1, \color{blue}{2, 3, 1}, 3, 2, \color{green}{2, 3}]$,
•$b = [\color{red}{1}, 1,\color{blue}{2, 3, 1}, 3, \color{green}{2, 3}, 2]$.
If a different segmentation had been used, the sent sequence might have been different.
The sequence is given. Could the sequence be sent over the network? In other words, is there such a sequence that converting to send it over the network could result in a sequence ?
格式
输入
The first line of input data contains a single integer () — the number of test cases.
Each test case consists of two lines.
The first line of the test case contains an integer () — the size of the sequence .
The second line of test case contains integers () — the sequence itself.
It is guaranteed that the sum of over all test cases does not exceed .
输出
For each test case print on a separate line:
•YES if sequence could be sent over the network, that is, if sequence could be obtained from some sequence to send over the network.
•NO otherwise.
样例
7
9
1 1 2 3 1 3 2 2 3
5
12 1 2 7 5
6
5 7 8 9 10 3
4
4 8 6 2
2
3 1
10
4 6 2 1 9 4 9 3 4 2
1
1
YES
YES
YES
NO
YES
YES
NO
提示
In the first case, the sequence could be obtained from the sequence with the following partition: $[\color{red}{1}] + [\color{blue}{2, 3, 1}] + [\color{green}{2, 3}]$. The sequence : $[\color{red}{1}, 1, \color{blue}{2, 3, 1}, 3, 2, \color{green}{2, 3}]$.
In the second case, the sequence could be obtained from the sequence with the following partition: . The sequence : .
In the third case, the sequence could be obtained from the sequence with the following partition: . The sequence : .
In the fourth case, there is no sequence such that changing for transmission over the network could produce a sequence .