vertex cover problem with dynamic programming
来源:互联网 发布:知乎城市冷漠 编辑:程序博客网 时间:2024/06/01 11:02
#include <iostream>#include <Windows.h>#include <vector>#include <algorithm>#include <numeric>using namespace std;struct node{int data;node *left, *right;int vc; // vc is the vertex cover count for the subtree.node(int d) : data(d), left(nullptr), right(nullptr), vc(0) {};};// recursive methodint vCover(node *root){if (root == nullptr)return 0;if (root->left == nullptr && root->right == nullptr)return 0;if (root->vc)return root->vc;// root is included in vertex coverint root_inc = 1 + vCover(root->left) + vCover(root->right);// root is excludedint root_exc = 0;if (root->left != nullptr)root_exc += 1 + vCover(root->left->left) + vCover(root->left->right);if (root->right != nullptr)root_exc += 1 + vCover(root->right->left) + vCover(root->right->right);root->vc = min(root_inc, root_exc);return root->vc;}int main(){node *root = new node(20);root->left = new node(8);root->left->left = new node(4);root->left->right = new node(12);root->left->right->left = new node(10);root->left->right->right = new node(14);root->right = new node(22);root->right->right = new node(25);cout << vCover(root) << endl;system("PAUSE");return 0;}
0 0
- vertex cover problem with dynamic programming
- Vertex Cover
- Vertex Cover
- Vertex Cover
- Dynamic Programming Solvable Problem
- Dynamic programming - LSC problem
- Vertex cover problem(NP)算法是多项式的?
- set cover和vertex cover
- SPOJ 1435. Vertex Cover
- Vertex Cover问题
- vertex cover approximate algorithm
- SCU4439-Vertex Cover
- SCU-4439-Vertex Cover
- HDU6150 Vertex Cover
- 【HDU6150】Vertex Cover (构造)
- hdu 6150 Vertex Cover
- 1134. Vertex Cover (25)
- 1134. Vertex Cover (25)
- 解析友盟错误分析
- Java中的类详解
- Java 实现导出excel表 POI
- APP后端数据接口注意事项
- 类型转换错误java.math.BigDecimal cannot be cast to java.lang.String
- vertex cover problem with dynamic programming
- jenkins远程部署使用shell脚本进行备份
- c中的inf和nan
- linq 判断时间出错
- cygwin 上编译和安装redis
- 特征值和特征向量理解
- SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
- javascript 数组对象方法
- QDockWidget