Permutation Pattern
Time limit2sMemory limit1024 MB
Given a permutation of length n (n up to 50), count the non-empty subsequences that avoid the 231 pattern.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Recursion
- Solved
- No attempts yet
Problem
A sequence of distinct numbers is called "without 231" if there is no triple with and . Bobo has a permutation of , and he can remove some elements from it (possibly none, but not all). Find the number of sequences without 231 among the resulting permutations.
Input
The input consists of several test cases, and the input ends at end-of-file. Each test case has two lines. The first line contains an integer . The second line contains integers .
Output
For each test case, output one integer, the number of sequences without 231.
Constraints
, and for each . In each input file, the sum of does not exceed 500.