Introduction#
The essence of is recursion, and many problems have a recursive form similar to that of , indicating that they share commonalities and can utilize the thinking methods of numbers, which opens a new window for us in problem-solving.
Definition#
Number of Binary Tree Types Problem#
Divide and conquer: left + self + right
We have the following definition
Valid Sequences#
instances of and instances of form terms , whose partial sums satisfy What is this sequence for ?
At first glance, it seems difficult, but let's analyze it carefully.
It seems inconvenient to obtain the result directly, so we use the principle of inclusion-exclusion.
We subtract the number of invalid sequences from the total.
Total Count#
Place instances of in a long sequence, with the rest being , thus the total count is .
Invalid Count#
First, we consider the invalid cases.
There is only one situation that leads to invalidity:
That is, during the process of some prefix sum, the partial sum first becomes less than zero.
Constructing Invalid Count#
Let be a set of valid solutions, and be any sequence (simultaneously satisfying that is missing exactly one and has ).
That is, .
Clearly, at this point, we have , which is a set of invalid solutions.
Warning
At this point, although it is an invalid solution, the counts of and in are both .
How do we distinguish between valid and invalid solutions?
We define (taking the complement of the sequence)
Now is a sequence that has one more and only one more (it has changed from having one less to one more).
Now is a sequence with instances of and instances of .
It seems we have distinguished them; let's verify the feasibility.
Consider whether it can be done without omission or duplication.
Carefully thinking, and form a bijective set.
This means that all invalid solutions correspond to such a .
So how do we count them?
We can enumerate the counts of or .
That is or .