HDOJ-1100 Trees made to order】的更多相关文章

Trees Made to Order Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7155   Accepted: 4094 Description We can number binary trees using the following scheme: The empty tree is numbered 0. The single-node tree is numbered 1. All binary tre…
题目来源:Trees Made to Order 题目大意:根据下面的规则给一棵二叉树编号: 规则1:如果二叉树为空,则编号为0: 规则2:如果二叉树只有一个节点,则编号为1: 规则3:所有含有m个节点的二叉树的编号小于所有含有m+1个节点的二叉树的编号: 规则4:如果一棵含有m个节点的二叉树(左子树为L,右子树为R)的编号为n,要想其它含有m个节点的二叉树的编号如果大于n,则需要满足两个条件中的任意一个:1.左子树的编号大于L的编号:2.左子树的编号等于L的编号,但是右子树的编号大于R的编号.…
http://www.cnblogs.com/keam37/p/3637717.html  keam所有 转载请注明出处 Problem Description We can number binary trees using the following scheme: 我们用下面的规则来给一颗二叉树编号: The empty tree is numbered 0. 空树编号为0. The single-node tree is numbered 1. 只有一个节点的树编号为1. All bin…
一.题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1100 二.题目分析 对二叉树的所有形态顺序编号,编号规则是:节点数越多的编号越大:节点数相等,左子树节点数越多的越大:节点数相等,左子树节点数也相等,则依此规则比较右子树. 现给定一个正整数,依题目要求输出对应编号的二叉树形态. 三.求解思路 由题目输出格式要求,很直观地联想到使用深度优先搜索dfs,以当前二叉树对应的编号为条件,依次递归输出左子树和右子树. 1 int main(void) {…
题目链接 中间计算的各种细节.有的细节没处理好,就wa了...主要思路就是根据卡特兰数列的: h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (n>=2) #include <cstdio> #include <string> #include <cstring> #include <queue> #include <map> #include <iostream> #inclu…
这题用到了卡特兰数,详情见:http://www.cnblogs.com/jackge/archive/2013/05/19/3086519.html 解体思路详见:http://blog.csdn.net/lvlu911/article/details/5425974 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cm…
http://poj.org/problem?id=1095 先求出n个节点数的二叉树的形态有多少种.卡特兰数f[n]=f[n-1]*(4*n-2)/(n+1);再递归求. #include <cstdio> #include <cstring> #include <algorithm> #define ll long long #define maxn 200 using namespace std; ll f[maxn]; int n,m; void inti()…
这题用到了卡特兰数,比较麻烦.关于卡特兰数的基本概念百度一下你就知道. 使用卡特兰数对数组元素进行分组之后,需要具体计算一下要求的是第几组的第几个数,然后向下递归. 首先来看利用卡特兰数分组: 从1开始前4个卡特兰数是 C[1]=1, C[2]=2, C[3]=5, C[4]=14  (C[0]也是有定义的,C[0]=1) 于是我们把第1个元素归为第1组,第2,3个元素归为第2组,4,5,6,7,8归为第3组,9到22归为第4组,这样分组就完成了 这里的每个元素,就对应着题目里的每一棵树.而卡特…
A full binary tree is a binary tree where each node has exactly 0 or 2 children. Return a list of all possible full binary trees with N nodes.  Each element of the answer is the root node of one possible tree. Each node of each tree in the answer mus…
A full binary tree is a binary tree where each node has exactly 0 or 2 children. Return a list of all possible full binary trees with Nnodes.  Each element of the answer is the root node of one possible tree. Each node of each tree in the answer must…