Dev.baelanche

[백준 6603] 로또 본문

Data Structure & Algorithm/PS - JAVA

[백준 6603] 로또

baelanche 2019. 6. 29. 17:28
반응형

 

중복되지 않으면서 오름차순인 수열을 완전탐색한다.

 

빈 줄을 끼워넣는 것을 유의한다.

 

public class Main {
    
    static int a[];
    static int k;
    static boolean f = true;
    
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        
        while(true) {
            st = new StringTokenizer(br.readLine());
            k = Integer.parseInt(st.nextToken());
            if(k == 0) break;
            a = new int[k];
            for(int i=0; i<k; i++)
                a[i] = Integer.parseInt(st.nextToken());
            
            if(!f) System.out.println();
            dfs(0, 0, "");
        }
    }
    
    public static void dfs(int idx, int cnt, String s) {
        if(cnt == 6) {
            f = false;
            System.out.println(s);
            return;
        }
        
        for(int i=idx; i<k; i++)
            dfs(i+1, cnt+1, s+a[i]+" ");
    }
}
반응형

'Data Structure & Algorithm > PS - JAVA' 카테고리의 다른 글

[백준 1547] 공  (0) 2019.06.29
[백준 14500] 테트로미노  (0) 2019.06.29
[백준 11866] 조세퍼스 문제 0  (0) 2019.06.29
[백준 4949] 균형잡힌 세상  (0) 2019.06.29
[백준 10773] 제로  (0) 2019.06.29
Comments