import java.util.Scanner;
public class Main {
static int n, m;
static int arr[] = new int [101];
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
m = scan.nextInt();
if (m == 1) {
dice1(1);
}
else if (m == 2) {
dice2(1, 1);
}
else if (m == 3) {
dice3(1);
}
}
private static void dice1(int level) {
int i;
if (level > n) {
output();
return;
}
else {
for (i = 1; i <= 6; i++) {
arr[level] = i;
dice1(level + 1);
}
}
}
private static void dice2(int level, int s) {
int i;
if (level > n) {
output();
return;
}
for (i = s; i <= 6; i++) {
arr[level] = i;
dice2(level + 1, i);
}
}
private static void dice3(int level) {
int i;
if (level > n) {
output();
return;
}
else {
for (i = 1; i <= 6; i++) {
if (!check(level, i)) {
continue;
}
arr[level] = i;
dice3(level + 1);
}
}
}
private static boolean check(int level, int a) {
// TODO Auto-generated method stub
int i;
for (i = 1; i < level; i++) {
if (arr[i] == a) {
return false;
}
}
return true;
}
private static void output() {
int i;
for (i = 1; i <= n; i++) {
System.out.printf("%d ", arr[i]);
}
System.out.printf("\n");
}
}
http://www.jungol.co.kr/bbs/board.php?bo_table=pbank&wr_id=449&sca=2080
'정올문제소스코드' 카테고리의 다른 글
1459 : 숫자고르기 (0) | 2021.12.05 |
---|---|
1175 : 주사위 던지기2 (0) | 2021.12.05 |
1161 : 하노이1 (0) | 2021.12.05 |
1309 : 팩토리얼 (0) | 2021.12.05 |
2858 : 쇠막대기 (0) | 2021.12.05 |