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. 微博,and java 多线程编程 入门到精通 将cpu 的那个 张振华

    http://down.51cto.com/data/2263476  java 多线程编程 入门到精通  将cpu 的那个 张振华 多个用户可以同时用一个 vhost,但是vhost之间是隔离的. ...

  2. 关于解决 http 状态码200,php 文件有输出,但是不显示模板文件的问题

    一 问题 给公司搭建一个在线测试站点之后,在浏览器地址栏输入 "http://xxx.xxx.xxx/index.php",页面什么都没显示.调出浏览器的开发者工具查看,http ...

  3. 超高逼格Log日志打印

    代码地址如下:http://www.demodashi.com/demo/12646.html 前言 Log日志的打印一直是一个比较头疼的事,怎样才能让自己的log显示更多信息,怎样才能让自己的log ...

  4. IDEA报compilation failed:internal java compiler error解决方法

    java complier 设置的问题  ,项目中有的配jdk1.6,有的配jdk1.7,版本不一样,导致这样的错误,提示这样的报错时,从file-Settings进入

  5. Excel2007制作直方图和正态分布曲线图

    对同一维度的数据分析数据分布范围及分布趋势,要通过制作直方图和正态分布曲线图体现. 例如:已知所有员工的日收入,分析员工收入分布情况(51.7,50.6,57.9,56.9,56.7,56.7,55. ...

  6. VBA小功能集合-判断列内是否有重复值

    1.判断列内是否有重复值: Dim arrT As Range Dim rng As Range Set arrT = Range("A:A")'判读A列单元格 For Each ...

  7. HTML5中两种方法实现客户端存储数据

    HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessionStorage - 针对一个 session 的数据存储 之前,这些都是由 coo ...

  8. 使用itchat分析自己的微信(1)

    1.准备工作 安装itchat pip install itchat参考 itchat内部函数 2.个人微信男女比例分析 ''' Have fun:itchat Author:杨 景 Time:201 ...

  9. DDD中的聚合和UML中的聚合以及组合的关系

    UML:聚合关系:成员对象是整体的一部分,但是成员对象可以脱离整体对象独立存在.如汽车(Car)与引擎(Engine).轮胎(Wheel).车灯(Light)之间的关系为聚合关系,引擎.轮胎.车灯可以 ...

  10. linux sublime python

    (三)配置python3编译环境 1.点击上部菜单栏Tools->Build System ->new Build System 2.点击之后,会出现一个空的配置文件,此时,往这个空配置文 ...