<> subject :

<>AC code :
#include <iostream> #include <algorithm> using namespace std; int n; const int
N= 16; int st[N]; int path[N]; void dfs(int u) { if (u == n) //
When from 0 At the beginning , In fact, the first floor doesn't care , therefore { // The termination condition is when u = n When for (int i = 0; i < n; i ++) if (st
[i] == 1) cout << path[i] << " "; cout << endl; return ; } // Select the number of this location path[u] =
u+ 1; // Storage path array st[u] = 1; // 1 Indicates that this number is selected dfs(u + 1); // Restore the site path[u] = 0; st[u] =
0; // 0 This layer has not been selected yet // Do not select this number st[u] = 2; dfs(u + 1); } int main() { cin >> n; dfs
(0); // Let's study how many trees there are first dfs tree , Obviously , There is only one tree here return 0; } // Easy to understand version #include <iostream> #
include <algorithm> #include <vector> using namespace std; const int N = 16; int
n; int st[N]; vector<vector<int>> ways; void dfs(int u) { if (u == n + 1) {
vector<int> way; for (int i = 1; i <= n; i ++) if (st[i] == 1) // If this layer has been selected way.
push_back(i); ways.push_back(way); // Pay attention to saving each tree into a large one vector in return ; } st[u] = 2;
// No choice dfs(u + 1); st[u] = 0; st[u] = 1; // choice dfs(u + 1); st[u] = 0; } int main
() { cin >> n; dfs(1); for (int i = 0; i < ways.size(); i ++) //
We use one vector How many trees are there dfs tree { for (int j = 0; j < ways[i].size(); j ++)// Path of each tree cout
<< ways[i][j] << " "; cout << endl; } return 0; }
<> supplement :

1, Deducing time complexity from data range

*
2, Common need to remember numbers
2 10 = 1000000 2^{10} = 1000000 210=1000000 10 ten thousand

2 16 = 25536 2^{16} = 25536 216=25536

2 15 = 32768 2^{15} = 32768 215=32768

2 63 = 1000 ten thousand ( 1 0 8 ) 2^{63} = 1000 ten thousand (10 ^ 8 ) 263=1000 ten thousand (108)

*
3, The four most common header files
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>
using namespace std;

Technology
©2019-2020 Toolsou All rights reserved,
C++ of string of compare usage Python Study notes ( one )evo Tool usage problems ——Degenerate covariance rank, Umeyama alignment is not possibleRISC-V_GD32VF103-TIMER0 timer interrupt java Array subscript variable _Java Basic grammar : array be based on stm32 Control four-wheel trolley motor drive ( one ) be based on redis Design of liking function Software engineering career planning mysql Query random data by conditions _MySQL Random query of several qualified records centos7 install RabbitMq