Created
January 8, 2018 14:18
-
-
Save developer-sdk/74cd1149005227c9b9c1f8ce1b8fab8d to your computer and use it in GitHub Desktop.
정올, 그리디, 2499
This file contains hidden or 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
| package sdk.jungol.greedy; | |
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.TreeSet; | |
| public class Problem2499 { | |
| static TreeSet<Integer> set = new TreeSet<>(); | |
| public static void main(String[] args) { | |
| int n = 7; | |
| int[] array = { 3, 1, 6, 2, 7, 30, 1 }; | |
| Arrays.sort(array); | |
| for (int num : array) | |
| set.add(num); | |
| int[] testArray = { 1, 2, 3, 4, 5 }; | |
| int[] visited = new int[5]; | |
| combi(testArray, visited, 0, 3); | |
| } | |
| static ArrayList<Integer> list = new ArrayList<>(); | |
| public static void combi(int[] array, int[] visited, int pivot, int size) { | |
| if (size == 0) { | |
| for (int num : list) | |
| System.out.printf("%2d", num); | |
| System.out.println(); | |
| return; | |
| } | |
| for (int i = pivot; i < array.length; i++) { | |
| if (visited[i] == 1) | |
| continue; | |
| list.add(array[i]); | |
| visited[i] = 1; | |
| combi(array, visited, pivot + 1, size - 1); | |
| list.remove(list.size() - 1); | |
| visited[i] = 0; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment