Given a permutation of n elements (1, 2, ..., n): A = (a1, a2, . . . , an). We define a sequence
P (A) = (p1, p2, . . . , pn−1) where pi = 0 if ai > ai+1 and pi = 1 if ai < ai+1. Given a permutation
B, find the number of all permutations C where P (C) = P (B) including the permutation B
itself.
The input text file contains several tests, each on a separate line. The first number in the test
is n (0 < n ≤ 1024) followed by n numbers representing the permutation all of them separated
by a single space. The last line in the input contains only 0 and should not be processed.
The output should be written on the standard output. For each line in the input (excluding the
last one, 0) you should write the result i.e. the number of the permutations having the same
value for P (A) when given the permutation A.
You may assume the result is less than 232.
2 1 2 4 1 3 2 4 0
1 5
Migrated from old NTUJ.
No. | Testdata Range | Score |
---|