Printing Sequences
시간 제한2초메모리 제한2048 MB
값이 1부터 K까지이고 K가 3 이하인 목표 수열이 주어질 때, PRINT 문을 K개 이하로 써서 중첩 REP 반복문으로 그 수열을 출력하는 프로그램을 만들 수 있는지 판정한다.
문제
Bessie is learning to code using a simple programming language. She first defines a valid program, then executes it to produce some output sequence.
Defining:
- A program is a nonempty sequence of statements.
- A statement is either of the form "PRINT " where is an integer, or "REP ", followed by a program, followed by "END," where is an integer that is at least 1.
Executing:
- Executing a program executes its statements in sequence.
- Executing the statement "PRINT " appends to the output sequence.
- Executing a statement starting with "REP " executes the inner program a total of times in sequence.
An example of a program that Bessie knows how to write is as follows.
REP 3
PRINT 1
REP 2
PRINT 2
END
END
The program outputs the sequence .
Bessie wants to output a sequence of () positive integers. Elsie challenges her to use no more than () "PRINT" statements. Note that Bessie can use as many "REP" statements as she wants. Also note that each positive integer in the sequence is no greater than .
For each of () independent test cases, determine whether Bessie can write a program that outputs some given sequence using at most "PRINT" statements.
입력
The first line contains .
The first line of each test case contains two space-separated integers, and .
The second line of each test case contains a sequence of space-separated positive integers, each at most , which is the sequence that Bessie wants to produce.
출력
For each test case, output "YES" or "NO" (case sensitive) on a separate line.