Created
August 28, 2021 05:27
-
-
Save yeopgi/c179aaefabaf5ee5b9d081bc14ffeea8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| const int MAX = 1000; | |
| int N; | |
| int d[4][MAX + 1]; | |
| int house[4][MAX + 1]; // [1] : red, [2] : green, [3] : blue | |
| int main(void) | |
| { | |
| ios_base::sync_with_stdio(false); | |
| cin.tie(nullptr); | |
| cin >> N; | |
| for (int i = 1; i <= N; i++) { | |
| cin >> house[1][i] >> house[2][i] >> house[3][i]; | |
| } | |
| for (int i = 1; i <= N; i++) { | |
| d[1][i] = min(d[2][i - 1], d[3][i - 1]) + house[1][i]; | |
| d[2][i] = min(d[1][i - 1], d[3][i - 1]) + house[2][i]; | |
| d[3][i] = min(d[2][i - 1], d[1][i - 1]) + house[3][i]; | |
| } | |
| cout << min(d[3][N], min(d[1][N], d[2][N])) << '\n'; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment