-
Notifications
You must be signed in to change notification settings - Fork 0
/
양궁대회.js
46 lines (37 loc) · 1001 Bytes
/
양궁대회.js
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
// Solution 1
function solution(n, info) {
let maxDifference = 0;
let ryonScoreList = Array.from({ length: 11 }, () => 0);
function shot(peachScore, ryonScore, count, index, board) {
if (n < count) {
return;
}
if (index > 10) {
const difference = ryonScore - peachScore;
if (difference > maxDifference) {
board[10] = n - count;
maxDifference = difference;
ryonScoreList = board;
}
return;
}
if (n > count) {
let subBoard = [...board];
subBoard[10 - index] = info[10 - index] + 1;
shot(
peachScore,
ryonScore + index,
count + info[10 - index] + 1,
index + 1,
subBoard
);
}
if (info[10 - index] > 0) {
shot(peachScore + index, ryonScore, count, index + 1, board);
} else {
shot(peachScore, ryonScore, count, index + 1, board);
}
}
shot(0, 0, 0, 0, ryonScoreList);
return maxDifference <= 0 ? [-1] : ryonScoreList;
}