[BOJ] 1149번 : RGB거리
2024. 8. 31. 15:15ㆍAlgorithm
1. problem :
https://www.acmicpc.net/problem/1149
2. solution 1:
#include <bits/stdc++.h>
using namespace std;
int n;
int d[1005][3];
int r[1005];
int g[1005];
int b[1005];
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> r[i] >> g[i] >> b[i];
d[1][0] = r[1];
d[1][1] = g[1];
d[1][2] = b[1];
for (int i = 2; i <= n; i++) {
d[i][0] = min(d[i - 1][1], d[i - 1][2]) + r[i];
d[i][1] = min(d[i - 1][0], d[i - 1][2]) + g[i];
d[i][2] = min(d[i - 1][0], d[i - 1][1]) + b[i];
}
cout << min(min(d[n][0], d[n][1]), d[n][2]);
}
source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x10/solutions/1149.cpp
basic-algo-lecture/0x10/solutions/1149.cpp at master · encrypted-def/basic-algo-lecture
바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.
github.com
'Algorithm' 카테고리의 다른 글
[BOJ] 11659번 : 구간 합 구하기 4 (0) | 2024.08.31 |
---|---|
[BOJ] 11726번 : 2 x n 타일링 (0) | 2024.08.31 |
[BOJ] 9095번 : 1,2,3 더하기 (0) | 2024.08.31 |
[BOJ] 1463번 : 1로 만들기 (0) | 2024.08.30 |
[BOJ] 7795번 : 먹을 것인가 먹힐 것인가 (0) | 2024.08.30 |