시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 256 MB | 16 | 3 | 3 | 23.077% |
You have a deck of N cards valued from 1 to N. The game starts with cards facing down in the "initial" location. There are also three other locations where you can play your cards face up (once they are face up at the top of any of the other piles): "goal", "helper" and "pile". You win the game once all the cards are placed on the goal in ascending order (N on the top). Rules:
What is the minimum number of type 4 moves you need to finish the game?
First line of the input contains an integer T (1 <= T <= 100) - the number of test cases. Each test case consists of two lines:
First line contains an integer N ( 1 <= N <= 1000)
Second line contains description of the "initial" deck. The first number is the value of the card at the bottom of the initial deck facing down (so the last card will be played first onto "pile"). This will be a permutation of the list of integers from 1 to N.
For each test case print the minimum number of type 4 moves you neeed to "win" the game on a separate line.
2 3 1 2 3 6 6 2 4 3 5 1
0 1