<p>Given an integer <code>n</code>, return <em>a list of all possible <strong>full binary trees</strong> with</em> <code>n</code> <em>nodes</em>. Each node of each tree in the answer must have <code>Node.val == 0</code>.</p>

<p>Each element of the answer is the root node of one possible tree. You may return the final list of trees in <strong>any order</strong>.</p>

<p>A <strong>full binary tree</strong> is a binary tree where each node has exactly <code>0</code> or <code>2</code> children.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/22/fivetrees.png" style="width: 700px; height: 400px;" />
<pre>
<strong>Input:</strong> n = 7
<strong>Output:</strong> [[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 3
<strong>Output:</strong> [[0,0,0]]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 20</code></li>
</ul>

/**
 * Definition for a binary tree node.
    * struct TreeNode {
    *     int val;
    *     TreeNode *left;
    *     TreeNode *right;
    *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
    *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
    * };
 */
class Solution {
public:
    void rec(vector<int> t,vector<vector<int>>& st,int ind,int maxv){
        int n = t.size();
        //cout << ind << " " << maxv << endl;
        if(maxv==0){
            st.push_back(t);
        }
        else if(maxv>=2){
            int sav = 0;
            for(int i=ind;i<n;i++){
                t.push_back(0);
                t.push_back(0);
                rec(t,st,i+sav+1,maxv-2);
                t.pop_back();
                t.pop_back();
                t.push_back(-1);
                t.push_back(-1);
                sav+=2;
            }
        }
    }
TreeNode* deserialize(vector<int>& t){
    queue<TreeNode*> q1;
    TreeNode* root = new TreeNode(0);
    q1.push(root);
    int cnt=1;
    int n = t.size();
    while(q1.size()!=0){
        TreeNode* cur = q1.front();
        q1.pop();
        if(t[cnt]!=-1){
            cur->left = new TreeNode(0);
            q1.push(cur->left);
        }
        cnt++;
        if(cnt==n)break;
        if(t[cnt]!=-1){
            cur->right = new TreeNode(0);
            q1.push(cur->right);
        }
        cnt++;
        if(cnt==n)break;
    }
    return root;
}
    vector<TreeNode*> allPossibleFBT(int n) {
        if(n==1) return {new TreeNode(0)};
        if(n%2!=1) return {}; 
        vector<vector<int>> st;
        vector<int> t;
        t.push_back(0);
        rec(t,st,0,n-1);
        vector<TreeNode*> st2;
        for(auto t1:st){
            /*for(auto t2:t1){
                cout << t2 << ",";
            }
            cout << endl;*/
            TreeNode* tmp = deserialize(t1); 
            st2.push_back(tmp);
        }
        return st2;
    }

};
45713