Muscardinus
양궁대회 본문
728x90
https://programmers.co.kr/learn/courses/30/lessons/92342
function solution(n, info) {
let maxDiff = 0;
let ryonInfo = new Array(11).fill(0);
const run = (peachScore, ryonScore, count, idx, board) => {
if (n < count) return;
if (idx > 10) {
let diff = ryonScore - peachScore;
if (diff > maxDiff) {
board[10] = n - count;
maxDiff = diff;
ryonInfo = board;
}
return;
}
if (n > count) {
let board2 = [...board];
board2[10 - idx] = info[10 - idx] + 1;
run(peachScore, ryonScore + idx, count + info[10 - idx] + 1, idx + 1, board2);
}
if (info[10 - idx] > 0) {
run(peachScore + idx, ryonScore, count, idx + 1, board);
} else {
run(peachScore, ryonScore, count, idx + 1, board)
}
}
run(0, 0, 0, 0, ryonInfo);
if (maxDiff <= 0) return [-1];
return ryonInfo;
}
728x90
'알고리즘 문제 > [프로그래머스] Lv2' 카테고리의 다른 글
주차 요금 계산 (0) | 2022.04.01 |
---|---|
게임 맵 최단거리 (0) | 2022.03.28 |
순위검색 (0) | 2022.02.02 |
거리두기 확인하기 (0) | 2022.01.28 |
행렬 테두리 회전하기 (0) | 2022.01.23 |
Comments