728x90
728x90
https://www.acmicpc.net/problem/2579
난이도: solved.ac 실버 3
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
int stairs[301];
int dp[301];
int main() {
int n, i;
scanf("%d", &N);
for (i = 1; i <= n; i++)
scanf("%d", &stairs[i]);
dp[1] = stairs[1];
dp[2] = stairs[1] + stairs[2];
for (i = 3; i <= n; i++)
dp[i] = max(dp[i - 2], dp[i - 3] + stairs[i - 1]) + stairs[i];
printf("%d", dp[n]);
return 0;
}
반응형