Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 백준 16935
- time complexity
- 백준 14391
- 프로그래머스 숫자의 표현 java
- java 내림
- 백준 18290
- 백준 4375
- java
- 프로그래머스 옹알이 java
- Algorithm
- Math.ceil()
- 백준 11723
- 프로그래머스 네트워크 java
- 0으로 채우기
- 알고리즘
- 백준 16927
- mysql
- java 반올림
- Codility
- java 올림
- 프로그래머스 연속된 수의 합 java
- 코딩테스트
- Arrays
- 자바
- sort
- 프로그래머스 도둑질 java
- 백준 17425
- 백준 15661
- 네트워크
- Math.floor()
Archives
- Today
- Total
취미처럼
[백준] 10819번 차이를 최대로 본문
https://www.acmicpc.net/problem/10819
10819번: 차이를 최대로
첫째 줄에 N (3 ≤ N ≤ 8)이 주어진다. 둘째 줄에는 배열 A에 들어있는 정수가 주어진다. 배열에 들어있는 정수는 -100보다 크거나 같고, 100보다 작거나 같다.
www.acmicpc.net
import java.util.*;
import java.io.*;
public class Main {
public static int N;
public static int[] arr;
public static int[] num;
public static boolean[] visit;
public static int max = Integer.MIN_VALUE;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
arr = new int[N];
num = new int[N];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < N; i++) {
num[i] = Integer.parseInt(st.nextToken());
}
visit = new boolean[N];
dfs(0);
System.out.println(max);
}
public static void dfs(int depth) {
if(depth == N) {
int sum = 0;
for(int i= 0; i < N-1; i++) {
sum += Math.abs(arr[i] - arr[i+1]);
}
max = Math.max(sum, max);
return;
}
for(int i = 0 ; i < N ; i ++ ) {
if(!visit[i]) {
visit[i] = true;
arr[depth] = num[i];
dfs(depth + 1);
visit[i] = false;
}
}
}
}
'Algorithm > 백준' 카테고리의 다른 글
[백준] 6603번 로또 (0) | 2021.03.04 |
---|---|
[백준] 10971번 외판원 순회 2 (0) | 2021.03.04 |
[백준] 10974번 모든 순열 (0) | 2021.03.04 |
[백준] 10973번 이전 순열 (0) | 2021.03.04 |
[백준] 10972번 다음 순열 (0) | 2021.03.04 |
Comments