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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Data Structure Binary Tree: Iterative Postorder Traversal

    http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/ #include <iostream> #i ...

  5. Data Structure Binary Tree: Morris traversal for Preorder

    http://www.geeksforgeeks.org/morris-traversal-for-preorder/ #include <iostream> #include <v ...

  6. 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 ...

  7. Data Structure Binary Tree: Boundary Traversal of binary tree

    http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/ #include <iostream> #include & ...

  8. 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 ...

  9. Data Structure Binary Tree: Populate Inorder Successor for all nodes

    http://www.geeksforgeeks.org/populate-inorder-successor-for-all-nodes/ #include <iostream> #in ...

随机推荐

  1. 我是怎样理解web页面的

    事实上web页面包括三部分东东 1.页面展示的元素(HTML) 2.页面元素展示的样式(CSS) 3.控制页面元素的交互(JavaScript) 不管页面多么复杂,从这三方面去看,都会得到清晰的认识的 ...

  2. ubuntu下USB连接Android手机

    初始工作:将Android手机通过usb连接到电脑,之后点击VM-Removable Devices-google Android - Connect,即可. 若通过usb连接到电脑,Removabl ...

  3. 利用CFAbsoluteTimeGetCurrent()计算时间差

    开发中,遇到计算时间差的问题,利用CFAbsoluteTimeGetCurrent()可以很方便的进行计算 实例: 场景:类似购物车中修改商品数量的功能,如下图所示,要求,修改完的数量,要同步到服务器 ...

  4. SQL Server变量赋值的方法

    SQL Server变量赋值我们经常会遇到,下面就为您介绍SQL Server变量赋值的两种方法,希望可以对您学习SQL Server变量赋值有所帮助. SQL Server中对已经定义的SQL Se ...

  5. java游戏开发之基础

    © 版权声明:本文为博主原创文章,转载请注明出处 游戏图形界面开发基础 AWT:(Abstract Window Toolkit,抽象窗口工具集) AWT中包含图形界面编程的基本类库,是Java语言G ...

  6. Hibernate学习之属性级别注解

    © 版权声明:本文为博主原创文章,转载请注明出处 属性级别注解 添加方式 1. 写在属性字段上面 2. 写在属性getter方法上面 @Id:必须,定义了映射到数据库表的主键属性,一个实体可以有一个或 ...

  7. java.long中的类和方法

    java.lang.Character.isUpperCase(char ch) 确定指定的字符是否为大写字符. java.lang.Character.toUpperCase()方法用法转换从Uni ...

  8. CoreAnimation的使用小结

    參考:http://www.cnblogs.com/wendingding/p/3801157.htmlhttp://www.cnblogs.com/wendingding/p/3802830.htm ...

  9. 我佩服-WPF(2)

    简单的学学WPF,我们知道他就是拖拉控件,一点也不难.假设公司真的使用WPF搞开发,你去面试,直接说WPF就是拖拉控件,那就慘了. 有些公司非常喜欢使用WPF.不不过比較简单.更重要的是全然做到了分离 ...

  10. HttpClient远程调用接口

    详细参考这个博文:http://www.cnblogs.com/itliucheng/p/5065619.html 一.get请求: //关键代码就这几行 String urlNameString = ...