본문 바로가기
알고리즘/DP

2579 계단오르기

by tryotto 2019. 7. 5.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int stair[305= { 0 };
int dp[305= { 0 };
 
int main() {
    int n;
    scanf("%d"&n);
 
    for (int i = 1; i <= n; i++) {
        scanf("%d"&stair[i]);
    }
 
    dp[1= stair[1];
    dp[2= stair[1+ stair[2];
    for (int i = 3; i <= n; i++) {
        dp[i] = stair[i] + max(dp[i - 3+ stair[i - 1], dp[i - 2]);
    }
    printf("%d", dp[n]);
}
cs


'알고리즘 > DP' 카테고리의 다른 글

2156 포도주 시식  (0) 2019.07.05
1003 피보나치 함수  (0) 2019.07.05
9095 1,2,3 더하기  (0) 2019.07.05
2193 이친수  (0) 2019.07.05
(미해결) buy lower 더블릿  (0) 2019.02.23