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. 一个RecycleView的强大adapter

    代码地址如下:http://www.demodashi.com/demo/12218.html 前言 一般我们要在mainActivity中利用RecycleView展示一个列表数据的时候,adapt ...

  2. java在linux上始终无法用jdbc跟myql连接

    确实手动在机器上连接mysql没问题的话,尝试下面的方法   a.重启网卡 b.重启系统

  3. spark插件入门完整版本

    1 在spark项目中添加source folder文件夹,取名为src/plugins/testplugin/src/java 2 在此文件夹下新建包名,取名为com.jivesoftware.sp ...

  4. ios 抓包工具 ios青花瓷charles

    iOS_青花瓷Charles抓包,ios青花瓷charles 使用青花瓷Charles抓取手机端的网络请求: 第一步,下载安装并打开Charles 第二步,去掉菜单[Proxy]以下的[Mac OSX ...

  5. svn解决冲突和commit

    当使用svn出现 svn: E155015: 提交失败(细节如下):svn: E155015: 提交终止: “/home/test.file” 处于冲突状态 解决办法: svn resolved /h ...

  6. visual studio 2010 LNK1123解决方式

    ------------------------------------------------------------Lysen----------------------------------- ...

  7. 简易web服务器(java版)

    //直接使用 ServerSocket 监听服务器端口,就能实现web服务器package ThreadPoolTest; import java.io.InputStream; import jav ...

  8. JDK自带的定时任务

    import java.util.TimerTask; /** * 实现定时任务 * */ public class MyTimerTask extends TimerTask { @Override ...

  9. Harbor配置ldap

    1.修改配置Harborp配置文件,共修改三处 1.1 auth_mode = ldap_auth 1.2 ldap_url = ldap://10.10.20.202 1.3 ldap_basedn ...

  10. The Pilots Brothers' refrigerator - poj 2965

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20325   Accepted: 7830   Special Judg ...