반응형
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=449&sca=99&sfl=wr_hit&stx=1169
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N, M;
static int[] temp;
static boolean[] mask;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
mask = new boolean[7];
temp = new int[7];
temp[0] = 1;
if(M == 1) {
dice1(1, 0);
} else if(M == 2) {
dice2(1, 0);
} else if(M == 3) {
dice3(1, 0);
}
}
public static void dice1(int start, int depth) {
if(depth == N) {
for(int i=1; i<=depth; i++) {
System.out.print(temp[i] + " ");
}
System.out.println();
return;
}
for(int i=1; i<=6; i++) {
temp[start] = i;
dice1(start+1, depth+1);
}
}
public static void dice2(int start, int depth) {
if(depth == N) {
for(int i=1; i<=depth; i++) {
System.out.print(temp[i] + " ");
}
System.out.println();
return;
}
for(int i=temp[start-1]; i<=6; i++) {
temp[start] = i;
dice2(start+1, depth+1);
}
}
public static void dice3(int start, int depth) {
if(depth == N) {
for(int i=1; i<=depth; i++) {
System.out.print(temp[i] + " ");
}
System.out.println();
return;
}
for(int i=1; i<=6; i++) {
if(mask[i]) continue;
temp[start] = i;
mask[i] = true;
dice3(start+1, depth+1);
mask[i] = false;
}
}
}
반응형
'알고리즘 > 문제풀이' 카테고리의 다른 글
[백준] 4179. 불! (0) | 2020.02.05 |
---|---|
[백준] 17136. 색종이 붙이기 (2) | 2020.02.05 |
[백준] 11559. Puyo Puyo (0) | 2020.02.01 |
[SWEA] 2007. 패턴 마디의 길이 (0) | 2020.01.29 |
[백준] 7568. 덩치 (0) | 2020.01.26 |