赞
踩
P5018 对称二叉树
题目传送门
这是一道经典的递归题,千万别被这题目给吓到了。
思路:
二叉树中的任意节点,都可能是一棵对称二叉树的根节点,那么就直接枚举1~n做根就行了。
从枚举的根开始,如果要生成对称二叉树,那左右子节点的结构及点值必须相同,接下来对于左右子节点的子节点也有相同的问题,那就是(如果要生成对称二叉树,那左右子节点的结构及点值必须相同)……。递归
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
using namespace std;
const int MAX=2147483647;
const int N=1e6+5;
int n,ans=1,v[N],l[N],r[N
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。