Data Structure Binary Tree: Largest Independent Set Problem
http://www.geeksforgeeks.org/largest-independent-set-problem/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; struct node {
int data;
struct node *left, *right;
node() : data(), left(NULL), right(NULL) { }
node(int d) : data(d), left(NULL), right(NULL) { }
}; int LISS(node *root) {
if (!root) return ;
int sum = ;
if (root->left) sum += LISS(root->left->left) + LISS(root->left->right);
if (root->right) sum += LISS(root->right->left) + LISS(root->right->right);
return max(sum, LISS(root->left) + LISS(root->right));
} int main() {
node *root = new node();
root->left = new node();
root->right = new node();
root->left->left = new node();
root->left->right = new node();
root->left->right->left = new node();
root->left->right->right = new node();
root->right->right = new node();
cout << LISS(root);
return ;
}
Data Structure Binary Tree: Largest Independent Set Problem的更多相关文章
- Data Structure Binary Tree: Lowest Common Ancestor in a Binary Tree
http://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/ #include <iostream> #in ...
- Data Structure Binary Tree: Print ancestors of a given binary tree node without recursion
http://www.geeksforgeeks.org/print-ancestors-of-a-given-binary-tree-node-without-recursion/ #include ...
- Data Structure Binary Tree: Convert a given Binary Tree to Doubly Linked List
http://www.geeksforgeeks.org/in-place-convert-a-given-binary-tree-to-doubly-linked-list/ #include &l ...
- Data Structure Binary Tree: Iterative Postorder Traversal
http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/ #include <iostream> #i ...
- Data Structure Binary Tree: Morris traversal for Preorder
http://www.geeksforgeeks.org/morris-traversal-for-preorder/ #include <iostream> #include <v ...
- Data Structure Binary Tree: Construct Full Binary Tree from given preorder and postorder traversals
http://www.geeksforgeeks.org/full-and-complete-binary-tree-from-given-preorder-and-postorder-travers ...
- Data Structure Binary Tree: Boundary Traversal of binary tree
http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/ #include <iostream> #include & ...
- Data Structure Binary Tree: Convert a given tree to its Sum Tree
http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/ #include <iostream> #include &l ...
- Data Structure Binary Tree: Populate Inorder Successor for all nodes
http://www.geeksforgeeks.org/populate-inorder-successor-for-all-nodes/ #include <iostream> #in ...
随机推荐
- 程序员不修复BUG怎么办
在测试过程中,难免遇到开发人员因为一些原因不想修改个别bug的情况.遇到这种问题时,该如何去推进开发修改bug呢? 一.现状分析 1.开发人员为啥不愿意修复BUG? (1)开发与测试对bug的定义理解 ...
- NSTimer注意内存泄露(真该死)
NSTimer可以用来执行一些定时任务,比较常用的方法就是: + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTar ...
- Google Code Jam 2014 Round 1 A:Problem C. Proper Shuffle
Problem A permutation of size N is a sequence of N numbers, each between 0 and N-1, where each numbe ...
- linux 进程线程
linux下进程的最大线程数.进程最大数.进程打开的文件数 ===========最大线程数============== linux 系统中单个进程的最大线程数有其最大的限制 PTHREAD_TH ...
- Template Method模式
模版方法模式,实际上就是指子类做方法实现,父类做算法实现. 通常情况下,子类继承父类,我们是站在子类的视角上来看父类的,目的不外乎下面三个 1,子类继承父类的方法 2,通过子类来增加方法,实现新的功能 ...
- XML5632 : Only one root element is allowed. Line: 1, Column 1
奇葩啊, 最后查出来是因为有一个svg文件名对不上...
- cocoapods 错误处理
error: RPC failed; curl 56 SSLRead() return error -36 [!] /usr/bin/git clone https://github.com/Coco ...
- centos7.0 增加/usr分区的容量减少home分区的大小
把/home内容备份,然后将/home文件系统所在的逻辑卷删除,扩大/root文件系统,新建/home:tar cvf /tmp/home.tar /home #备份/homeumount /home ...
- 【BZOJ1132】[POI2008]Tro 几何
[BZOJ1132][POI2008]Tro Description 平面上有N个点. 求出所有以这N个点为顶点的三角形的面积和 N<=3000 Input 第一行给出数字N,N在[3,3000 ...
- [原创]css设置禁止中文换行
white-space: nowrap; 如有需要还可以设置word-break,word-wrap配合.