https://www.acmicpc.net/problem/2579
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <stdio.h> #include <stdlib.h> int stairCount; int stairScore[300]; int totalScore[300]; int max(int a, int b) { return a > b ? a : b; } int main() { scanf("%d\n", &stairCount); for(int i = 0; i < stairCount; i++){ scanf("%d", &stairScore[i]); } totalScore[0] = stairScore[0]; totalScore[1] = totalScore[0] + stairScore[1]; totalScore[2] = max(stairScore[0], stairScore[1]) + stairScore[2]; for(int i = 3; i < stairCount; i++){ totalScore[i] = max(totalScore[i - 3] + stairScore[i - 1], totalScore[i - 2]) + stairScore[i]; } printf("%d\n", totalScore[stairCount-1]); return 1; } | cs |
i 번째 계단으로 올라가는 경우의 수는
i - 3 , i - 1, i 번째 계단을 밟거나
i - ? , i - 2, i 번째 계단을 밟는 것이 존재한다.
처음 0, 1, 2번째 계단에 대한 값을 구한 후
3번째 계단 부터는 이 공식에 따라 점수를 비교하고 최대값을 찾는다.
'#DevStudy > 문제풀이' 카테고리의 다른 글
[Baekjoon] 9625 - BABBA (0) | 2016.10.13 |
---|---|
[Baekjoon] 1932 - 숫자삼각형 (0) | 2016.10.12 |
[Baekjoon] 1149 - RGB (0) | 2016.10.11 |
[P.C] 3. 여행 (The trip) (0) | 2016.09.23 |
[P.C] 2. 지뢰찾기 (Minesweeper) (0) | 2016.09.23 |
댓글