티스토리 뷰
반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package BACKJOON; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.StringTokenizer; | |
public class back_15649 { | |
public static int[] arr; | |
public static boolean[] visit; | |
public static StringBuilder sb = new StringBuilder(); | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
StringTokenizer st = new StringTokenizer(br.readLine()); | |
int N = Integer.parseInt(st.nextToken()); | |
int M = Integer.parseInt(st.nextToken()); | |
arr = new int[M]; | |
visit = new boolean[N]; | |
dfs(N,M,0); | |
System.out.println(sb); | |
} | |
public static void dfs(int N, int M, int depth){ | |
if( depth == M){ | |
for(int val : arr) | |
sb.append(val).append(' '); | |
sb.append('\n'); | |
return; | |
} | |
for(int i=0; i<N; i++){ | |
if(!visit[i]){ | |
visit[i]=true; | |
arr[depth] = i+1; | |
dfs(N,M,depth+1); | |
visit[i] = false; | |
} | |
} | |
} | |
} |

반응형
'알고리즘 > 백준' 카테고리의 다른 글
1260번 백준 (0) | 2021.04.20 |
---|---|
백준 9251 (0) | 2021.04.20 |
[back_11404] (0) | 2021.03.29 |
[1197]최소 스패닝 트리(MST) / 스패닝 트리(STP) (0) | 2021.02.14 |
[백준] 1330번 두 수 비교하기 (0) | 2021.02.09 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 매트랩
- Matlab
- 프로그래머스
- 수학
- kakao
- Solid
- Spring
- docker
- Algorithm
- 스프링
- 알고리즘
- ajax
- 그래프
- 자바
- security
- 스프링부트
- interview
- OOP
- springboot
- C언어
- 백준
- 면접
- CS
- nginx
- 디자인패턴
- 릿코드
- spring-cloud
- java
- JPA
- 자격증
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함