An algorithm is requested to calculate all balanced binary trees which can be built with $N$ nodes, having exactly $L$ leaves. A balanced tree is a binary tree in which the difference between the heights of the left and right subtrees is at most 1, and the subtrees are themselves balanced.
I tried to use dynamic programming to calculate the number for the subtrees created from any subsequence of $1..N$. However, without building each possible subtree and calculating its height and differentiating the height of the subtrees from each other, it can't distinguish the balanced subtrees. Moreover, the sum of their leaves must be exactly $L$. There are many constraints, and I couldn't come up an algorithm, either a working nor an optimum one.
Could you please guide me?
Source: Assignment of Advanced Algorithms, Fall 2018, Tehran University