For this array of different (unique) integers, I want to know the number of BSTs in all permutations with the right largest leverage of length k. (If k = 3, root-> right-> right is the leaf node)
(According to my current requirement, I cannot afford an algorithm with a cost greater than N ^ 3)
Two identical BSTs generated from different permutations are considered different.
So far my approach is:
Assume the function:
F(arr) = {a1, a2, a3...}
where a1 is the number of arrays with k = 1, a2 is the number of arrays with k2, etc.
F (arr [1: n]) = for i in the range from 1 to n (1 + df * F (subar, where each element is greater than arr [i])) Where df is the dynamic factor (n-1) C (the number of elements is less than arr [i])
I am trying to create dp to solve the problem
- Array Sort
- dp [i] [i] = 1
- (j i-1 1) dp [j] [i] = dp [j] [i-1],
ex: arr {4, 3, 2, 1}, dp
arr[i] 4 3 2 1
+---+---+---+---+
k = 1 | 1 | 1 | 2 | 6 |
+---+---+---+---+
k = 2 | - | 1 | 3 |11 |
+---+---+---+---+
k = 3 | - | - | 1 | 6 |
+---+---+---+---+
k = 4 | - | - | - | 1 |
+---+---+---+---+
verification(n!) 1 2 6 24
, , , , .
.
edit: , 3D- dp. .
edit: col 3 dp