[BOJ] 1149번 : RGB거리

2024. 8. 31. 15:15Algorithm

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