One, subset tree
subset Tree : The corresponding solution space is called a subset tree When the given problem is to find a subset that satisfies a certain property from the set S of n elements. For example, the solution space tree for the 0-1 knapsack problem of that item is a subset tree. Such subset problems usually have 2^n leaf nodes, the total number of nodes is 2^ (n+1)-1. Any algorithm that traverses a subset tree requires an O (2^n) calculation time.
\
void Backtrack (int t) { if (t>N) output (x); Else for (int i=0; i<=1; i++) { x[t]=i; if (Legal (T)) backtrack (t+1);} }
Second, arrange the tree
Arrange trees : When the given question is to determine the arrangement of n elements satisfying a certain nature, the corresponding solution space tree is called an arrangement tree . An arrangement tree usually has a n! leaf node. So traversing the arrangement tree requires O (n!) The calculation time.
void Backtrack (int t) { if (t>N) output (x); Else for (int i=t;i<=n;i++) { swap (x[t], x[i]); if (Legal (T)) backtrack (t+1); Swap (X[t], x[i]);
MORE: http://blog.csdn.net/liufeng_king/article/details/8762073
Subsets and issues:
Title Description: An example of a subset and a problem is 〈s,t〉. wherein, s={1 x, 2 x, ..., n x} is a set of positive integers, and C is a positive integer. Subsets and problems determine if there is a subset of S S1, so that the sum of each element in S1 equals C.
Http://blog.sina.com.cn/s/blog_7865b083010100dd.html
http://blog.csdn.net/sjf0115/article/details/6996804
http://blog.csdn.net/neilhappy/article/details/7313608
Subset Tree and permutation tree (subset and problem) of backtracking