할껀하고놀자
[백준] N과 M (2) 본문
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 |
package ssafy0401;
import java.util.Scanner;
public class sol15649 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int [] arr = new int [N]; for (int i = 0; i < arr.length; i++) { arr[i] = i+1; } int [] output = new int[N]; boolean [] visited = new boolean [N]; perm(arr,output,visited,0,N,M); } static void perm(int [] arr,int [] output,boolean [] visited, int depth,int n,int r) { if(depth==r) { for (int i = 0; i < r-1; i++) { if(output[i]>output[i+1]) return; } for (int i = 0; i < r; i++) System.out.print(output[i]+" "); System.out.println(); } for (int i = depth; i < n; i++) { if(!visited[i]) { visited[i] = true; output[depth] = arr[i]; perm(arr,output,visited,depth+1,n,r); visited[i] = false; } } } }
|
cs |
'[IT] > 백준' 카테고리의 다른 글
[백준] 2908번 상수 (0) | 2019.05.25 |
---|---|
[백준] N과 M (1) (0) | 2019.04.01 |
[백준] 암호 만들기 (0) | 2019.04.01 |
[백준] 외판원 순회 2 (0) | 2019.04.01 |
[9095] 1,2,3 더하기 (0) | 2018.09.03 |