Let's count the binary tree together

1. We know that binary tree access generally involves dynamic programming, because the left subtree also has left and right subtrees.
The idea of using dynamic programming to save costs is almost the same as using a dp[i][j] to store information. i is the number of nodes and j is the number of leaf nodes. Obviously j<i;
dynamic programming generally requires an initial value, and others are derived from the initial value, as well as a state transition equation. First, the initial value d[0][0] =1 means the root node is a leaf node,
dp【1】【1】=1 means that if the node is 1 and no node is the same;
we know that if there are x nodes on the left and y leaf nodes on the left, then there are
ix-1 nodes, jy leaf nodes, then the state transition equation comes out
dp[i][j]=dp[i][j]+dp[ix-1][jy]*dp[x][y ];`

#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
using namespace</

Guess you like

Origin blog.csdn.net/qq_43634564/article/details/107286780