티스토리 뷰
그리디 알고리즘을 이용하여 저울 문제를 해결할 수 있다.
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
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; | |
} | |
} | |
} |
반응형
'알고리즘 > 정올' 카테고리의 다른 글
[정올][다이나믹] 1848 극장좌석 (0) | 2017.04.11 |
---|---|
[정올][백트래킹] 1027 좋은 수열 (0) | 2016.10.09 |
[정올][다이나믹] 2000 동전교환 (0) | 2016.10.04 |
[정올] [문제은행] 1942 하얀모자 (0) | 2016.09.23 |
[정올][다이나믹] 1871 줄세우기 (0) | 2016.09.21 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 다이나믹
- 정올
- HDFS
- Tez
- oozie
- Python
- build
- airflow
- 알고리즘
- Linux
- yarn
- mysql
- 오류
- S3
- emr
- 백준
- SQL
- error
- Hadoop
- HIVE
- hbase
- AWS
- nodejs
- SPARK
- java
- ubuntu
- 하둡
- bash
- 파이썬
- 하이브
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함