์™„์ „ํƒ์ƒ‰_week3๐Ÿค”

๊ธฐ๋ฆฐ์ดยท2021๋…„ 2์›” 24์ผ
0

์•Œ๊ณ ๋ฆฌ์ฆ˜๐Ÿ”‘

๋ชฉ๋ก ๋ณด๊ธฐ
8/17

ํˆฌ๋น…์Šค ๊ณผ์ œ์˜€๋˜ 3๋ฌธ์ œ์˜ ์™„์ „ ํƒ์ƒ‰ ๋ฌธ์ œ์ด๋‹ค.

์—ฟํŒ”์•„์š”

๋ฌธ์ œ๋ฅผ ์ดํ•ดํ•˜๋Š” ๊ฒŒ ํž˜๋“ค์—ˆ๋‹ค. ์ž˜๋ฆฐ ์—ฟ์˜ ๊ธธ์ด๋ฅผ ์™„์ „ํƒ์ƒ‰ํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค.

n, c, f= map(int, input().split())
arr = []
for _ in range(n):
    arr.append(int(input()))
m = max(arr)
all_lst = []
for i in range(1, m+1): # i๋Š” ๊ธธ์ด!!!!!!
    prices = 0
    for ii in arr:
        if ii%i != 0:
            price = (ii//i)*i*f - (ii//i)*c
        else:
            price = (ii//i)*i*f - (ii//i-1)*c
        prices += price
    all_lst.append(prices)
print(max(all_lst))

IP์ฑ„๊ตด๊ธฐ

์ฒ˜์Œ์—๋Š” DPS/DFS๋ฅผ ์ด์šฉํ•ด ํ’€์–ด์•ผ ํ•˜๋‚˜..?ํ–ˆ๋Š”๋ฐ
DPS/DFS/๋ฐฑํŠธ๋ž˜ํ‚น ๊ด€๋ จ ๋ฏธ๋กœ ๋ฌธ์ œ์—์„œ ์ด๋™ํ•˜๋ฉด์„œ ์žฌ๊ท€ํ•จ์ˆ˜๊ฐ€ ์–ด๋–ป๊ฒŒ ๋Œ์•„๊ฐ€๋Š” ์ง€ ์ตํ˜”๋˜ ๊ฒŒ ๋„์›€์ด ๋œ ๋ฌธ์ œ๋‹ค.

pan = []
for _ in range(4):
    pan.append(list(input().split()))
dx=[-1, 0, 1, 0]
dy=[0, 1, 0, -1]
path = []
paths = []
def move(x, y,depth):
    global path
    global paths
    if depth ==9:
        # paths.append(path.copy())
        paths.append(' '.join(map(str, path)))
        return
    else:
        for i in range(4):
            xx=x+dx[i]
            yy=y+dy[i]
            if 0<=xx<=3 and 0<=yy<=3:
                path.append(pan[x][y])
                # path += pan[x][y]
                move(xx, yy, depth+1)
                path.pop()

for rownum in range(4):
    for colnum in range(4):
        move(rownum, colnum,1)
# print(paths)
# print(len(paths))
print(len(set(paths)))

๊ดด๋„

itertools์˜ Combination, ์กฐํ•ฉ์„ ์ด์šฉํ•ด์„œ ํ‘ผ ๋ฌธ์ œ๋‹ค.

from itertools import combinations
n, m = map(int, input().split())
arr = list(input().split())
arr = [int(i) for i in arr]
lst = list(combinations(arr, 3))
l = [sum(i) for i in lst if sum(i) <= m]
print(max(l))
profile
์ค‘์š”ํ•œ ๊ฒƒ์€ ์†๋ ฅ์ด ์•„๋‹ˆ๋ผ ๋ฐฉํ–ฅ์„ฑ

0๊ฐœ์˜ ๋Œ“๊ธ€