algorithm/문제 풀이

백준 10974번 (모든 순열) 자바 Java

ssoheeh 2024. 4. 6. 22:34

 

 

 

완전탐색으로 구현

import java.util.*;
import java.io.*;


public class Main {

    static int N;
    static Vector<Integer> v;
    static Stack<Integer> st;
    static void print(){
        if(st.size()==N) {
            for(int num:st){
                System.out.print(num+" ");
            }
            System.out.println();
            return;
        }
        for(int i=1;i<N+1;i++){

            if(!st.contains(i)){
                st.add(i);
                //System.out.println(i);
                print();
                st.pop();
            }
        }

    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        N = Integer.parseInt(br.readLine());
        st = new Stack<>();
        print();
        
        br.close();

    }
}

쓸 수 있는 문제가 많으니 확실히 이해하고 암기하기..!