https://www.acmicpc.net/problem/6603
간단한 dfs문제입니다.
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int arr[13]; int t = 0; void dfs(int start, vector<int>& v){ v.push_back(arr[start]); if(v.size() == 6){ for(int i = 0; i < 6; i++) cout << v[i] << ' '; cout << endl; return; } for(int i = start+1; i < t; i++){ dfs(i,v); v.pop_back(); } } int main(){ while(1){ cin >> t; if(t==0) break; for(int i = 0; i < t; i++) cin >> arr[i]; for(int i = 0; i < t; i++){ vector<int> v; dfs(i,v); } cout << endl; } } | cs |
반응형
'프로그래밍 > 문제풀이' 카테고리의 다른 글
[bfs] 백준 1389 케빈 베이컨의 6단계 법칙 (0) | 2019.03.27 |
---|---|
[dfs] 백준 2644 촌수계산 (0) | 2019.03.27 |
[bfs, dfs] 백준 2573 빙산 (0) | 2019.03.25 |
[bfs, dfs] 백준 2667 단지번호붙이기 (0) | 2019.03.24 |
[dfs] 백준 2606 바이러스 (0) | 2019.03.22 |