[BOJ] 2096 내려가기

Time Lapse :NONE

2096.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

#include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;
int N;
int arr[3];
int dp[3][2];
int choose[3];

int main(void)
{
cin>>N;
memset(dp,0,sizeof(dp));
for(int i=0;i<N;i++)
{
cin>>arr[0]>>arr[1]>>arr[2];

choose[0]=max(arr[0]+dp[0][0],arr[0]+dp[1][0]);

choose[1]=max(arr[1]+dp[2][0],max(arr[1]+dp[0][0],arr[1]+dp[1][0]));

choose[2]=max(arr[2]+dp[1][0],arr[2]+dp[2][0]);

dp[0][0]=choose[0];
dp[1][0]=choose[1];
dp[2][0]=choose[2];

choose[0]=min(arr[0]+dp[0][1],arr[0]+dp[1][1]);

choose[1]=min(arr[1]+dp[2][1],min(arr[1]+dp[0][1],arr[1]+dp[1][1]));

choose[2]=min(arr[2]+dp[1][1],arr[2]+dp[2][1]);

dp[0][1]=choose[0];
dp[1][1]=choose[1];
dp[2][1]=choose[2];
}
cout<<max(max(dp[0][0],dp[1][0]),dp[2][0])<<" "<<min(min(dp[0][1],dp[1][1]),dp[2][1])<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2096/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.