Created
January 26, 2022 15:18
-
-
Save beng9re/24548687f4124f3259eac14e545161ea to your computer and use it in GitHub Desktop.
순열과 조합 (백트래킹)
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
public static void permutation(int idx) { | |
if(idx == R) { | |
return; | |
} | |
for(int i = 0; i < list.length; ++i) { | |
if(visited[i]) continue; | |
resulList[idx] = list[i]; | |
visited[i] = true; | |
permutation(idx+1); | |
visited[i] = false; | |
} | |
} |
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
// 백트래킹 사용 | |
// 사용 예시 : combination(arr, visited, 0, n, r) | |
static void combination(int[] arr, boolean[] visited, int start, int n, int r) { | |
if (r == 0) { | |
print(arr, visited, n); | |
return; | |
} | |
for (int i = start; i < n; i++) { | |
visited[i] = true; | |
combination(arr, visited, i + 1, n, r - 1); | |
visited[i] = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment