diff --git a/Recursion/P29_25_SubsetGen b/Recursion/P29_25_SubsetGen new file mode 100755 index 0000000..e5b953a Binary files /dev/null and b/Recursion/P29_25_SubsetGen differ diff --git a/Recursion/P29_25_SubsetGen.cpp b/Recursion/P29_25_SubsetGen.cpp new file mode 100644 index 0000000..801086c --- /dev/null +++ b/Recursion/P29_25_SubsetGen.cpp @@ -0,0 +1,47 @@ +//Generate subset +#include +#include +using namespace std; +//m: 本次递归选原数组第几个 +//n: 本次递归数组长度 +//l: 给定数组长度 +template +T* sub(int m ,int n, int l, T* x){ + T* tmp = new T [l]; + if(m == l){ + for(int i = 0; i < l; i++){ + cout << tmp[i] << endl; + } + return tmp; + + } + //不选a[i] + sub(m + 1, n, l, x); + + //选a[i] + tmp[n] = x[m]; + sub(m + 1, n + 1, l, x); + + +} + +int main(){ + //cin >> n; + int n = 5; + int num = pow(2 ,n); + double** p; + p = new double* [num]; + for(int i = 0; i < num ; i++){ + p[i] = new double[n]; + } + double arr[] = {1, 2, 3, 4, 5}; + sub(0, 0, 5, arr); + return 0; +} + + + + + + +