From 84da12bb0c1f3fcb0d94911cb34f0e9ee5e6d2d8 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 15 Jun 2026 18:16:58 +0900 Subject: [PATCH] =?UTF-8?q?16637=20:=20=EA=B4=84=ED=98=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=98=EA=B8=B0=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ16637/BOJ16637_V1.cpp | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/week3/BOJ16637/BOJ16637_V1.cpp diff --git a/src/week3/BOJ16637/BOJ16637_V1.cpp b/src/week3/BOJ16637/BOJ16637_V1.cpp new file mode 100644 index 0000000..cf15ad4 --- /dev/null +++ b/src/week3/BOJ16637/BOJ16637_V1.cpp @@ -0,0 +1,55 @@ + #include + using namespace std; + int N; + string inp_string; + vector operators; + vector num; + int max_num = INT_MIN; + int calculate(char op, int a, int b) { + if (op == '+') { + return a + b; + } else if (op == '-') { + return a - b; + } else { + return a * b; + } + } + + void solve(int idx, int cur_num) { + if (idx == num.size()-1) { + max_num = max(max_num, cur_num); + return; + } + + solve(idx+1, calculate(operators[idx], cur_num, num[idx+1])); + if (idx + 2 <= num.size()-1) { + int temp = calculate(operators[idx+1], num[idx+1], num[idx+2]); + solve(idx+2, calculate(operators[idx], cur_num, temp)); + } + return; + } + + int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> N; + cin >> inp_string; + + for (int i = 0; i < N; i++) { + if (i%2 == 0) { + num.push_back(inp_string[i] - '0'); + } else { + operators.push_back(inp_string[i]); + } + } + + solve(0,num[0]); + + cout << max_num << '\n'; + + + return 0; + } \ No newline at end of file