-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboj16637.cpp
46 lines (38 loc) · 894 Bytes
/
boj16637.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
41
42
43
44
45
46
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int INF = 2e9;
inline void Quick_IO(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int maxValue = -INF;
string s;
int N;
int calc(int a, char op, int b){
if(op=='*') return a*b;
else if(op=='+') return a+b;
else return a-b;
}
void solve(int left, int opIndex){
if(opIndex>=(int)s.size()){
maxValue = max(left, maxValue);
return;
}
int res1 = calc(left, s[opIndex], s[opIndex+1]-'0');
solve(res1, opIndex+2);
if(opIndex+3<(int)s.size()){
int temp = calc(s[opIndex+1]-'0', s[opIndex+2], s[opIndex+3]-'0');
int res2 = calc(left, s[opIndex], temp);
solve(res2, opIndex+4);
}
}
int main(){
Quick_IO();
cin>>N>>s;
solve(s[0]-'0', 1);
cout<<maxValue<<"\n";
return 0;
}