ABOUT ME

Today
Yesterday
Total
  • 0320 중복순열 구하기_DFS
    TIL 2025. 3. 20. 23:32
    // 중복 순열 구하기 문제
    package org.example.infrenJavaCodingTest;
    
    import java.util.Scanner;
    
    public class chap9_4 {
        static int[] pm;
        static int n , m;
    
        public void DFS(int L){
            if(L==m){
                for(int x : pm) System.out.print(x+" ");
                System.out.println();
            }
            else{
                // n 만큼
                for(int i=1; i<=n; i++)
                    pm[L] = i;
                    DFS(L+1);
                }
            }
        }
    
        public static void main(String[] args) {
            // 중복순열 -> 호출이 n 번
            chap9_4 T = new chap9_4();
            Scanner kb = new Scanner(System.in);
            n=kb.nextInt();
            m=kb.nextInt();
            pm=new int[m];
            T.DFS(0);
        }
    }
    

    'TIL' 카테고리의 다른 글

    20240324 DFS  (0) 2025.03.24
    20240225  (0) 2025.02.25
    1013  (0) 2024.10.13
    0726  (0) 2024.07.27
    0725  (0) 2024.07.26
Designed by Tistory.