#include <iostream>
using namespace std;
int cost[1000][3];
long long costDP[1000][3];
long long result[3];
//long long result = 1000 * 10000 + 1;
void makeDP(int N)
{
for (int j = 0; j < 3; j++)
{
costDP[0][0] = 1000 * 10000 + 1;
costDP[0][1] = 1000 * 10000 + 1;
costDP[0][2] = 1000 * 10000 + 1;
costDP[0][j] = cost[0][j];
for (int i = 1; i < N; i++)
{
costDP[i][0] = min(costDP[i - 1][1], costDP[i - 1][2]) + cost[i][0];
costDP[i][1] = min(costDP[i - 1][0], costDP[i - 1][2]) + cost[i][1];
costDP[i][2] = min(costDP[i - 1][0], costDP[i - 1][1]) + cost[i][2];
}
costDP[N - 1][j] = 1000 * 10000 + 1;
result[j] = min(costDP[N - 1][0], costDP[N - 1][1]) > costDP[N - 1][2] ? costDP[N - 1][2] : min(costDP[N - 1][0], costDP[N - 1][1]);
/* for (int i = 0; i < 3; i++)
{
if (j == i)
continue;
result = min(result, costDP[N - 1][i]);
}
*/
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> cost[i][0] >> cost[i][1] >> cost[i][2];
}
makeDP(N);
long long resultCost = min(result[0], result[1]) > result[2] ? result[2] : min(result[0], result[1]);
cout << resultCost;
}
์ญ์ ์ต์์ ์ ๋ฐ๋ณด๊ฐ ๋ง์ใท
RGB๊ฑฐ๋ฆฌ1์์ ๋ง์ ๋ถ๋ถ ์ ๊ฒฝ๋ ์์ฐ๊ณ ๋์ฒด ์ ํ๋ฆฐ๊ฑด์ง ํ์ฐธ์ ์ณ๋ค๋ดค๋๋ฐ costDP ๋ฐฐ์ด ํ ๋น์ 2๋ก ์คฌ์ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ์๋๊ทผ๋ฐ ์ ๋ง์๊ฑด๋ฐ 1์์๋ ์ง์ง ์ด์ด๊ฐ ์๋ค.....
'๐ก๐ธ๐ธ๐ถ๐ฃ: ๐๐๐๐๐๐พ๐๐ฝ๐ > ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ ํ์ด' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ14889 : ์คํํธ์ ๋งํฌ (Silver 3) (0) | 2021.08.20 |
---|---|
BOJ 2503 : ์ซ์์ผ๊ตฌ (Silver 5) (0) | 2021.08.20 |
BOJ1149 : RGB๊ฑฐ๋ฆฌ (Silver 1) (0) | 2021.08.17 |
BOJ11660 : ๊ตฌ๊ฐ ํฉ ๊ตฌํ๊ธฐ 5 (Silver 1) (0) | 2021.08.15 |
BOJ2012 : ๋ฑ์๋งค๊ธฐ๊ธฐ (Silver 3) (0) | 2021.08.13 |