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==0break;
        
        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


반응형

+ Recent posts