Skip to content

Commit

Permalink
boj: 15651 풀이
Browse files Browse the repository at this point in the history
Closed #57
  • Loading branch information
suhyunsim committed Apr 24, 2021
1 parent 0f82cfe commit d3c4a3d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/main/java/com/poogle/BOJ/Q15651/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main.java.com.poogle.BOJ.Q15651;

import java.util.Scanner;

public class Main {
// static boolean[] c = new boolean[10]; 중복을 방지하기 위한 배열을 사용하지 않도록 함
static int[] a = new int[10];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
System.out.println(go(0, n, m));
}

private static StringBuilder go(int index, int n, int m) {
if (index == m) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < m; i++) {
sb.append(a[i]);
if (i != m - 1) sb.append(" ");
}
sb.append("\n");
return sb;
}
StringBuilder ans = new StringBuilder();
for (int i = 1; i <= n; i++) {
// if (c[i]) continue;
// c[i] = true;
a[index] = i;
ans.append(go(index + 1, n, m));
// c[i] = false;
}
return ans;
}
}

0 comments on commit d3c4a3d

Please sign in to comment.