본문 바로가기
카테고리 없음

[python] 백준 2579번: 계단오르기

by brown_board 2023. 1. 6.
728x90

https://www.acmicpc.net/problem/2579

 

2579번: 계단 오르기

계단 오르기 게임은 계단 아래 시작점부터 계단 꼭대기에 위치한 도착점까지 가는 게임이다. <그림 1>과 같이 각각의 계단에는 일정한 점수가 쓰여 있는데 계단을 밟으면 그 계단에 쓰여 있는 점

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sys
 
#sys.stdin = open("input2.txt",'r')
input=sys.stdin.readline
 
= int(input())
score = []
stair = [0 for _ in range(n)]
for i in range(n):
    score.append(int(input()))
 
stair[0= score[0]
 
for i in range(1,n):
    if i == 1:
        stair[1= stair[0+ score[1]
    elif i==2:
        stair[2= max(stair[0]+score[2],score[1]+score[2])
    else:
        stair[i] = max(stair[i-3]+score[i-1]+score[i],stair[i-2]+score[i])
print(stair[n-1])
 
cs

 

 

728x90

댓글