Algorithm 문제풀이
[BOJ] 백준 10819 - 차이를최대로 (JAVA)
cjsong
2019. 4. 28. 21:36
순열 방식을 swap 해줬습니다.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main10819_차이를최대로{
static int[] arr;
static int result;
static int num =0;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
arr = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
nPr(0,N);
System.out.println(num);
}
public static void nPr(int len , int r ) { //순열
if(len == r) {
result = 0;
for (int i = 0; i < arr.length-1; i++) {
}
if(num<result) {
num = result;
}
return;
}
for (int i = len; i < arr.length; i++) {
int temp = arr[len];
arr[len] = arr[i];
arr[i] = temp;
nPr(len +1, r);
temp = arr[len];
arr[len] = arr[i];
arr[i] = temp;
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |