We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents aa5a80d + 7a5f97d commit 2ee7f80Copy full SHA for 2ee7f80
[Week16 - Recursion&Backtracking]/이현동/1662
56.3 KB
[Week16 - Recursion&Backtracking]/이현동/1662.cpp
@@ -0,0 +1,44 @@
1
+#include <iostream>
2
+#include <string>
3
+
4
+using namespace std;
5
6
+bool visited[51] = {
7
+ false,
8
+};
9
10
+int dfs(string &s, int idx)
11
+{
12
+ int cnt = 0;
13
+ for (int i = idx; i < s.size(); i++)
14
+ {
15
+ if (s[i] == '(' && !visited[i])
16
17
+ visited[i] = true;
18
+ int num = s[i - 1] - '0';
19
+ cnt--;
20
+ cnt += num * dfs(s, i + 1);
21
+ }
22
+ else if (s[i] == ')' && !visited[i])
23
24
25
+ return cnt;
26
27
+ else if (!visited[i])
28
29
30
+ cnt++;
31
32
33
34
35
+}
36
+int main()
37
38
+ string s;
39
+ cin >> s;
40
+ int ans = dfs(s, 0);
41
+ cout << ans << endl;
42
43
+ return 0;
44
0 commit comments