File tree Expand file tree Collapse file tree 1 file changed +72
-0
lines changed
Expand file tree Collapse file tree 1 file changed +72
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ class Solution {
6+ // 각 과녁판 점수를 얻냐, 못얻냐 -> 2^10 == 1024가지. 다 해보면 끝.
7+ static boolean [] win = new boolean [11 ];
8+ static int [] ans = {- 1 };
9+ static int largestDiff = 0 ;
10+ static int total;
11+ static int [] target;
12+
13+
14+ public int [] solution (int n , int [] info ) {
15+ total = n;
16+ int [] answer = {};
17+ target = info;
18+ doRecursive(0 );
19+ answer = ans;
20+ return answer;
21+ }
22+
23+ public void doRecursive (int num ){
24+ if (num == 11 ){
25+ process();
26+ return ;
27+ }
28+
29+ win[num] = true ;
30+ doRecursive(num+ 1 );
31+ win[num] = false ;
32+ doRecursive(num+ 1 );
33+ }
34+
35+
36+ public void process (){
37+ int [] curArr = new int [11 ];
38+ int curLeft = total;
39+ int pointDiff = 0 ;
40+
41+ for (int i = 0 ; i < 10 ; i++ ){
42+ int point = 10 - i;
43+ int minimum = target[i]+ 1 ;
44+ if (! win[i]) {
45+ if (target[i] != 0 ) pointDiff -= point;
46+ continue ;
47+ }
48+ if (curLeft < minimum)return ;
49+ curArr[i] = minimum;
50+ curLeft -= minimum;
51+ pointDiff += point;
52+
53+ }
54+ curArr[10 ] = curLeft;
55+
56+ if (pointDiff > largestDiff){
57+ largestDiff = pointDiff;
58+ ans = curArr;
59+ return ;
60+ }
61+
62+ if (pointDiff != 0 && pointDiff == largestDiff){
63+ for (int i = 10 ; i >= 0 ; i-- ){
64+ if (ans[i] == curArr[i]) continue ;
65+ if (ans[i] < curArr[i]) ans = curArr;
66+ else return ;
67+ }
68+
69+ }
70+ }
71+ }
72+ ```
You can’t perform that action at this time.
0 commit comments