-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDFS.cpp
More file actions
55 lines (49 loc) · 938 Bytes
/
DFS.cpp
File metadata and controls
55 lines (49 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Created by ASUS on 2023/5/19.
//
//
// Created by ASUS on 2023/5/19.
//
#include <algorithm>
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
//class Solution {
//public:
// int numTilePossibilities(string tiles) {
//
// }
//};
char s[50];
void DFS(string strs,int step){
static int n=strs.size();
if(strs.size()==1){
// cout<<strs[0]<<endl;
s[step] = strs[0];
for (int i = 1; i <= n; i++) {
cout << setw(5) << s[i]; // 保留5个场宽
}
cout << endl;
return;
}
else{
for (int i = 0; i < strs.size(); ++i) {
// cout<<strs[i];
s[step] = strs[i];
string t=strs;
t.erase(i,1);
DFS(t,step+1);
}
}
}
int main()
{
string s={'a','b','c','d'};
DFS(s,1);
return 0;
}