[Solution] Sending a Sequence Over the Network Codeforces Solution
The sequence is sent over the network as follows:
- 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);
- for each segment, its length is written next to it, either to the left of it or to the right of it;
- the resulting sequence is sent over the network.
For example, we needed to send the sequence . Suppose it was split into segments as follows: . Then we could have the following sequences:
- ,
- ,
- ,
- .
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.
You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive response).
No comments:
Post a Comment