Given a number N. The task is to find the number of permutations of 1 to N such that no three terms of the permutation form an increasing subsequence.
Input : N = 3 Output : 5 Valid permutations : 132, 213, 231, 312 and 321 and not 123 Input : N = 4 Output : 14
The above problem is an application of Catalan numbers. So, the task is to only find the n’th Catalan Number. First few Catalan numbers are 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, … (considered from 0th number)
Below is the program to find Nth Catalan Number:
- Minimum number of elements which are not part of Increasing or decreasing subsequence in array
- Count permutations that are first decreasing then increasing.
- Longest common subsequence with permutations allowed
- Longest Increasing Subsequence using BIT
- Longest Increasing Odd Even Subsequence
- Longest Common Increasing Subsequence (LCS + LIS)
- Print all Increasing Subsequence of a List
- Longest Increasing Subsequence Size (N log N)
- Printing Maximum Sum Increasing Subsequence
- Number of quadruples where the first three terms are in AP and last three terms are in GP
- Construction of Longest Increasing Subsequence(LIS) and printing LIS sequence
- Find the Increasing subsequence of length three with maximum product
- Length of the longest increasing subsequence such that no two adjacent elements are coprime
- Divide array into increasing and decreasing subsequence without changing the order
- Check if the first and last digit of the smallest number forms a prime
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.