recursive 로 짜면 편하긴 한데 뭔가 이상하다고 느꼈었음;;
가장 큰 path, 가장 작은 path 찾는 간단한 DP
//Thanks to shfshfdl
//dp w/o recursive fuction
#include <iostream>
#define DEBUG_KML 0
#define MIN_KML(a, b) (((a) < (b)) ? (a) : (b))
#define MAX_KML(a, b) (((a) > (b)) ? (a) : (b))
using namespace std;
int main() {
#ifdef DEBUG_KML
freopen("sample_input.txt", "r", stdin);
#endif
int N;
cin >> N;
int min_dp[3] = { 0,0,0 };
int max_dp[3] = { 0,0,0 };
int i;
for (i = 0; i < N; i++) {
char board[3];
cin >> board[0] >> board[1] >> board[2];
board[0] -= '0'; board[1] -= '0'; board[2] -= '0';
int cur[3];
cur[0] = MIN_KML(min_dp[0], min_dp[1]) + board[0]; // left
cur[1] = MIN_KML(MIN_KML(min_dp[0], min_dp[1]), min_dp[2]) + board[1]; // center
cur[2] = MIN_KML(min_dp[1], min_dp[2]) + board[2]; // right
min_dp[0] = cur[0];
min_dp[1] = cur[1];
min_dp[2] = cur[2];
cur[0] = MAX_KML(max_dp[0], max_dp[1]) + board[0]; // left
cur[1] = MAX_KML(MAX_KML(max_dp[0], max_dp[1]), max_dp[2]) + board[1]; // center
cur[2] = MAX_KML(max_dp[1], max_dp[2]) + board[2]; // right
max_dp[0] = cur[0];
max_dp[1] = cur[1];
max_dp[2] = cur[2];
}
max_dp[0] = MAX_KML(max_dp[1], max_dp[0]);
max_dp[0] = MAX_KML(max_dp[2], max_dp[0]);
min_dp[0] = MIN_KML(min_dp[1], min_dp[0]);
min_dp[0] = MIN_KML(min_dp[2], min_dp[0]);
//print out results
cout << max_dp[0] << " " << min_dp[0] << endl;
return 0;
}