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. SpringMVC传值(对象或字符串)给前台js

    java对象到js对象 1.先使用Jackson把对象转换成json串 ObjectMapper objectMapper = new ObjectMapper(); String json = ob ...

  2. 《windows核心编程》 在应用程序中使用虚拟内存

    Microsoft Windows 提供了以下三种机制来对内存进行操控: 虚拟内存 最适合用来管理大型对象数组或大型结构数组 内存映射文件 最适合用来管理大型数据流(通常是文件),以及在同一台机器上运 ...

  3. Lua学习十一----------Lua迭代器

    © 版权声明:本文为博主原创文章,转载请注明出处 Lua迭代器 - 迭代器(iterator)是一种对象,它能够用来遍历标准模板库容器中的部分或全部元素,每个迭代器对象代表容器中的确定的地址 - Lu ...

  4. 170621 - Android ADB forward端口映射和reverse反向代理 使用笔记

    个人理解 forward:端口映射 将本地PC指定Port端口,映射到设备手机指定Port端口上.以便解决 PC -> Phone 的访问问题PC 作为Client客户端 可以任意访问 Phon ...

  5. Android sdk 更新失败解决方发整理

    解决办法: 设置本地hosts windows里hosts位置在C:\Windows\System32\drivers\etc,找到hosts文件 直接在hosts文件的最后加一行: 74.125.2 ...

  6. [译]GLUT教程 - 移动镜头2

    Lighthouse3d.com >> GLUT Tutorial >> Input >> Move the Camera II 本节的最后一个示例是回顾.现在我们 ...

  7. pwd 命令

    Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置. ...

  8. excel批量取消隐藏工作表

    按下"Alt+F11"键,在打开的"Microsoft Bisual Basic"窗口中,选择"插入——模块".,复制下面的代码,按F5键运 ...

  9. MHA常用命令

    .查看ssh登陆是否成功 masterha_check_ssh --conf=/etc/masterha/app1.cnf .查看复制是否建立好 masterha_check_repl --conf= ...

  10. OpenCv for Android 环境搭建

    最近工作需要这样的功能 如下图 要在类似功能在android上实现 然后实现成这样 这两张图来自博客:图像校正—透视变换 可惜他用的是C/C++语言写的调用opencv,我参考了下他写的方案就想到了a ...