ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

11054๋ฒˆ: ๊ฐ€์žฅ ๊ธด ๋ฐ”์ดํ† ๋‹‰ ๋ถ€๋ถ„ ์ˆ˜์—ด

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

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

 ์ด ๋ฌธ์ œ๋Š” 11053 ๊ฐ€์žฅ ๊ธด ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด11722 ๊ฐ€์žฅ ๊ธด ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„ ์ˆ˜์—ด๋ฅผ ์ดํ•ดํ•˜๊ณ  ์žˆ๋‹ค๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค.  ํŠน์ • ์ง€์ ์„ ์„ ํƒํ•˜์˜€์„ ๋•Œ, ์ฆ๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„๊ณผ ๊ฐ์†Œํ•˜๋Š” ๋ถ€๋ถ„์˜ ํ•ฉ์ด ๊ฐ€์žฅ ํฐ ๊ฒฝ์šฐ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋œ๋‹ค.

 

์ฝ”๋“œ

from sys import stdin

if __name__ == '__main__':
    n = int(stdin.readline())
    nums = list(map(int, stdin.readline().split()))

    forward = [1] * n
    backward = [1] * n
    max_len = 0

    for i in range(1, n):
        for j in range(i):
            if nums[j] < nums[i]:
                forward[i] = max(forward[i], forward[j] + 1)

            if nums[n - j - 1] < nums[n - i - 1]:
                backward[n - i - 1] = max(backward[n - i - 1], backward[n - j - 1] + 1)

    for f_cnt, b_cnt in zip(forward, backward):
        cur_len = f_cnt + b_cnt
        max_len = cur_len if cur_len > max_len else max_len

    print(max_len - 1)
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€