forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproDFS1.java
More file actions
60 lines (41 loc) · 1.47 KB
/
proDFS1.java
File metadata and controls
60 lines (41 loc) · 1.47 KB
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
52
53
54
55
56
57
public class proDFS1 {
static int plusAndMinus[] = {1, -1};
static int answer = 0;
static int[] Globalnumbers;
static int count =0;
public static void main(String[] args) {
int[] number= {1,1,1,1,1,1,1};
int target = 3;
System.out.println(solution(number, target));
}
public static int solution(int[] numbers, int target) {
int level = 0;
int total = 0;
Globalnumbers = numbers;
DFS(plusAndMinus[0],target, level, total);
DFS(plusAndMinus[1],target, level, total);
return answer;
}
public static void DFS(int plus_minus, int target ,int level, int total)
{
count++;
//연산
total = total + plus_minus*Globalnumbers[level];
//마무리
if(level == Globalnumbers.length-1)
{
System.out.println("카운트 : " + count);
System.out.println("비교전 : " + total + " " + target);
if(target == total)
{
System.out.println(total +"비교후 토탈");
answer++;
return;
}
System.out.println(total +"비교후 정답 아닌것");
return;
}
DFS(plusAndMinus[0], target, level+1, total);
DFS(plusAndMinus[1], target, level+1, total);
}
}