Post

๐ŸฆŠ ์–‘๊ถ ๋Œ€ํšŒ

1. ๋ฌธ์ œ ๋งํฌ

์–‘๊ถ ๋Œ€ํšŒ



2. ์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from itertools import product

def solution(n, info):
    MAX = 0
    answer = [-1]
    # ์—ญ๋ฐฉํ–ฅ ์ˆœํšŒ
    info.reverse()
    # ๊ฒฐ๊ณผ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ˆœํšŒ
    for result in product([True, False], repeat=11):
        apeach_sum = sum(info[i] + 1 for i in range(11) if result[i])
        # ํ™”์‚ด ๊ฐœ์ˆ˜๊ฐ€ ์ผ์น˜ํ• ๋•Œ๋งŒ
        if apeach_sum <= n:
            apeach = sum(i for i in range(11) if not result[i] and info[i])
            ryan = sum(i for i in range(11) if result[i])
            sub = ryan - apeach
            if MAX < sub:
                MAX = sub
                answer = [info[i]+  1 if result[i] else 0 for i in range(11)]
                # ๋‚จ์€ ํ™”์‚ด์„ ์ œ์ผ ๋‚ฎ์€ ์ ์ˆ˜์— ๋„ฃ์Œ
                answer[0] += n - apeach_sum
    answer.reverse()
    return answer
  • ์ •ํ™•์„ฑ

    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
    
      ์ฑ„์ ์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
      ์ •ํ™•์„ฑ  ํ…Œ์ŠคํŠธ
      ํ…Œ์ŠคํŠธ 1 ใ€‰	ํ†ต๊ณผ (5.00ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 2 ใ€‰	ํ†ต๊ณผ (4.42ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 3 ใ€‰	ํ†ต๊ณผ (4.50ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 4 ใ€‰	ํ†ต๊ณผ (3.25ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 5 ใ€‰	ํ†ต๊ณผ (4.74ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 6 ใ€‰	ํ†ต๊ณผ (8.74ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 7 ใ€‰	ํ†ต๊ณผ (3.15ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 8 ใ€‰	ํ†ต๊ณผ (2.56ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 9 ใ€‰	ํ†ต๊ณผ (3.23ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 10 ใ€‰	ํ†ต๊ณผ (2.70ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 11 ใ€‰	ํ†ต๊ณผ (2.81ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 12 ใ€‰	ํ†ต๊ณผ (3.00ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 13 ใ€‰	ํ†ต๊ณผ (3.61ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 14 ใ€‰	ํ†ต๊ณผ (6.26ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 15 ใ€‰	ํ†ต๊ณผ (4.50ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 16 ใ€‰	ํ†ต๊ณผ (5.48ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 17 ใ€‰	ํ†ต๊ณผ (3.25ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 18 ใ€‰	ํ†ต๊ณผ (2.42ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 19 ใ€‰	ํ†ต๊ณผ (4.58ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 20 ใ€‰	ํ†ต๊ณผ (7.69ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 21 ใ€‰	ํ†ต๊ณผ (4.42ms, 10.3MB)
      ํ…Œ์ŠคํŠธ 22 ใ€‰	ํ†ต๊ณผ (4.79ms, 10.1MB)
      ํ…Œ์ŠคํŠธ 23 ใ€‰	ํ†ต๊ณผ (4.13ms, 10.2MB)
      ํ…Œ์ŠคํŠธ 24 ใ€‰	ํ†ต๊ณผ (9.17ms, 10.4MB)
      ํ…Œ์ŠคํŠธ 25 ใ€‰	ํ†ต๊ณผ (4.27ms, 10.3MB)
      ์ฑ„์  ๊ฒฐ๊ณผ
      ์ •ํ™•์„ฑ: 100.0
      ํ•ฉ๊ณ„: 100.0 / 100.0
    

3. ํ•ด์„ค

  • ํ•ด์„ค

    product ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ชจ๋“  ์กฐ๊ฑด ์ˆœํšŒ

    ์ด๊ธธ ๋•Œ๋Š” ์–ดํ”ผ์น˜์˜ ํ™”์‚ด ๊ฐœ์ˆ˜ + 1 ๊ฐœ ๋งŒํผ ํ•ฉ์„ ๊ตฌํ•˜๊ณ 

    ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ™”์‚ด๋ณด๋‹ค ์ ์„ ๊ฒฝ์šฐ์—๋งŒ ํ•ฉ๊ณ„๋ฅผ ๋น„๊ต

    ๋น„๊ตํ•œ ํ•ฉ๊ณ„๊ฐ€ ์ตœ๋Œ“๊ฐ’์ผ ๊ฒฝ์šฐ ๋ฐฐ์—ด์— ๋ฐ˜์˜

    ๋‹จ ๋งˆ์ง€๋ง‰์— ๋‚จ์€ ํ™”์‚ด์„ ๋ชจ๋‘ ์ œ์ผ ์ ์€ ์ ์ˆ˜(0์ )์— ๋ฐ˜์˜์‹œ์ผœ์•ผ ํ•จ

This post is licensed under CC BY 4.0 by the author.