일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 에라토스테네스의 체
- BFS
- DFS
- fsb
- House of Orange
- 큐
- ROP
- syscall
- 동적 계획법
- tcache
- 이진 탐색
- 브루트 포스
- 수학
- 이분 탐색
- 백트래킹
- 스위핑 알고리즘
- 다이나믹 프로그래밍
- 연결리스트
- heap
- 포맷스트링버그
- 이진트리
- 투 포인터
- RTL
- OOB
- off by one
- 문자열 처리
- 스택
- 완전 탐색
- 분할 정복
- BOF
Archives
- Today
- Total
SDJ( 수돈재 아님 ㅎ )
[C] 2579 - 계단 오르기 본문
문제 링크 : 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
|
#include <stdio.h>
#include <string.h>
#define max(a,b) (a > b ? a : b)
#pragma warning(disable:4996)
int dp[10005];
int stair[10005];
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];
dp[3] = max(stair[1] + stair[3], stair[2] + stair[3]);
if (n <= 3) {
printf("%d",dp[n]);
return 0;
}
for (int i = 4; i <= n; ++i)
dp[i] = max(dp[i - 3] + stair[i - 1] + stair[i], dp[i - 2] + stair[i]);
printf("%d", dp[n]);
}
|
'알고리즘 > Backjoon' 카테고리의 다른 글
[C] 1149 - RGB거리 (0) | 2020.01.11 |
---|---|
[C] 11726 - 2×n 타일링 (0) | 2020.01.11 |
[Python3] 1912 - 연속합 (0) | 2020.01.11 |
[C++] 1010 - 다리 놓기 (0) | 2020.01.10 |
[C++] 1309 - 동물원 (0) | 2020.01.10 |
Comments