๐Ÿ ํŒŒ์ด์ฌ ์ƒ์ดˆ์งœ

[BOJ][Python] ๋ฐฑ์ค€ 11055๋ฒˆ: ๊ฐ€์žฅ ํฐ ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด (Silver II)

์„ ๋‹ฌ 2024. 10. 26. 03:05
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

์ˆ˜์—ด A๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ทธ ์ˆ˜์—ด์˜ ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด ์ค‘์—์„œ ํ•ฉ์ด ๊ฐ€์žฅ ํฐ ๊ฒƒ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.
์˜ˆ๋ฅผ ๋“ค์–ด, ์ˆ˜์—ด A = {1, 100, 2, 50, 60, 3, 5, 6, 7, 8} ์ธ ๊ฒฝ์šฐ์— ํ•ฉ์ด ๊ฐ€์žฅ ํฐ ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์€ A = {1, 100,2,50,60, 3, 5, 6, 7, 8} ์ด๊ณ , ํ•ฉ์€ 113์ด๋‹ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ์ˆ˜์—ด A์˜ ํฌ๊ธฐ N (1 ≤ N ≤ 1,000)์ด ์ฃผ์–ด์ง„๋‹ค.
๋‘˜์งธ ์ค„์—๋Š” ์ˆ˜์—ด A๋ฅผ ์ด๋ฃจ๊ณ  ์žˆ๋Š” Ai๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ Ai≤ 1,000)

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— ์ˆ˜์—ด A์˜ ํ•ฉ์ด ๊ฐ€์žฅ ํฐ ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด์˜ ํ•ฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

ํ’€์ด

# input
n = int(input())
a = list(map(int, input().split()))

# dp
dp = a[:]

for i in range(n):
    for j in range(i):
        if a[j] < a[i] and dp[i] < dp[j] + a[i]:
            dp[i] = dp[j] + a[i]

# ouput
print(max(dp))
๋ฐ˜์‘ํ˜•