BOJ_S3_15651
๐ [S3_15651] N๊ณผM(3)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static StringTokenizer st;
static int N,M;
static StringBuilder sb;
static boolean[] v;
static int[] arr;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
sb = new StringBuilder();
st = new StringTokenizer(br.readLine(), " ");
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
arr = new int[M];
v = new boolean[N];
go(0);
System.out.println(sb);
}
static void go(int idx) {
if(idx == M) {
for(int i=0; i<M; i++) {
sb.append(arr[i]+1).append(" ");
}
sb.append("\n");
return;
}
for(int i=0; i<N; i++) {
v[i] = true;
arr[idx] = i;
go(idx+1);
v[i] = false;
}
}
}
๐ค ๋์ ์๊ฐ
์ด ๋ฌธ์ ๋ ๋ถ๋ถ์งํฉ์ ๋ชจ๋ ๊ฒฝ์ฐ๋ฅผ ๊ตฌํ๋ ๋ฌธ์ ์ด๋ค.
๊ทธ๋์ int ๋ฐฐ์ด๊ณผ boolean ๋ฐฐ์ด์ ์ด์ฉํด ์ฌ๊ท๋ฅผ ์ฌ์ฉํด ๊ตฌํด์ฃผ์๋ค.
๋ถ๋ถ์งํฉ์ ๋ชจ๋ ๊ฒฝ์ฐ์ ์์ ๋ํ ์ค๋ช
์ ์ฌ๊ธฐ์ ์๋ค.
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ๋ฌธ์ ์ด๋ค.