文章

34

粉丝

261

获赞

10

访问

10.1k

头像
吃糖果 题解:构建二叉树解决,二叉树的叶子结点个数就是方案个数
fzh VIP
P1197 北京大学上机题
发布于2024年3月19日 12:47
阅读数 132

#include<bits/stdc++.h>
using namespace std;
typedef struct TNode {

    int val;
    struct TNode* rchild, * lchild;

}*Tree;

void BuildTree(Tree& t, int val)
{

    if (val <0) return;
    t = new TNode;
    t->val = val;
    t->lchild = NULL;
    t->rchild = NULL;
    BuildTree(t->lchild, val - 1);
    BuildTree(t->rchild, val - 2);
}
//获取叶子结点个数
void GetLeaveNum(Tree t,int &result)
{

    if (t == NULL) return;
    if (t->lchild == NULL && t->rchild == NULL) result++;
    GetLeaveNum(t->lchild, result);
    GetLeaveNum(t->rchild, result);

 


}

 

int main()
{
    int n;
    while (cin >> n)
    {
        ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发