양궁대회 (재귀)

2023. 6. 27. 21:02·Coding Test/programmers
728x90
from copy import deepcopy

max_diff, max_board = 0, []


def solution(n, info):
    def dfs(ascore, lscore, cnt, idx, board):
        global max_diff, max_board
        if cnt > n:
            return
        if idx > 10:
            diff = lscore - ascore
            if diff > max_diff:
                board[10] = n - cnt
                max_board = board
                max_diff = diff
            return
        if cnt < n:
            board2 = deepcopy(board)
            board2[10 - idx] = info[10 - idx] + 1
            dfs(ascore, lscore + idx, cnt + info[10 - idx] + 1, idx + 1, board2)

        board1 = deepcopy(board)

        if info[10 - idx] > 0:
            dfs(ascore + idx, lscore, cnt, idx + 1, board1)
        else:
            dfs(ascore, lscore, cnt, idx + 1, board1)

    dfs(0, 0, 0, 0, [0] * 11)
    return max_board if max_board else [-1]
728x90
저작자표시 비영리 변경금지 (새창열림)
'Coding Test/programmers' 카테고리의 다른 글
  • 파괴되지 않은 건물 (누적합, 2차원 합배열)
  • 주차 요금 계산 (구현)
  • 양궁대회 (조합, 완전 탐색)
  • 양과 늑대 (DFS)
Karla Ko
Karla Ko
𝘾𝙤𝙣𝙩𝙞𝙣𝙪𝙤𝙪𝙨𝙡𝙮 𝙄𝙢𝙥𝙧𝙤𝙫𝙞𝙣𝙜, 𝘾𝙤𝙣𝙨𝙩𝙖𝙣𝙩𝙡𝙮 𝘿𝙚𝙫𝙚𝙡𝙤𝙥𝙞𝙣𝙜 𝙔𝙚𝙨!
    250x250
  • Karla Ko
    karlaLog
    Karla Ko
  • 전체
    오늘
    어제
    • Total (467)
      • Spring (19)
      • JPA (4)
      • Cloud & Architecture (15)
        • Kubernetes (5)
        • Docker (3)
        • MSA (2)
        • GCP (1)
        • AWS (4)
      • Devops (1)
      • Message Queue (4)
        • Kafka (2)
        • RabbitMQ (2)
      • Git (4)
      • DB (4)
      • Java (9)
      • Python (4)
      • CS (11)
        • OS (8)
        • Network (2)
        • Algorithm (1)
      • Coding Test (392)
        • programmers (156)
        • Graph (43)
        • DP (37)
        • Search (31)
        • Tree (13)
        • Data Structure (26)
        • Combination (12)
        • Implement (18)
        • Geedy (23)
        • Sort (7)
        • Math (21)
        • geometry (2)
  • 블로그 메뉴

    • 홈
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    파이썬
    최대공약수
    최소신장트리
    재귀
    정렬
    큐
    알고리즘
    조합
    프로그래머스
    구현
    트리
    덱
    그리디
    Algorithm
    최단거리
    구간합
    백준
    BFS
    월간코드챌린지
    LIS
    이분탐색
    자료구조
    스택
    플로이드워셜
    다익스트라
    DP
    동적계획법
    그래프
    DFS
    힙
  • hELLO· Designed By정상우.v4.10.3
Karla Ko
양궁대회 (재귀)
상단으로

티스토리툴바