Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<vector>
- using namespace std;
- int main() {
- string s;
- cin >> s;
- long long n = s.size();
- vector < vector < long long > > a(n + 1, vector < long long > (n + 1, 0));
- a[0][0] = 1;
- for (int i = 1; i <= n; i++) {
- for (int j = 0; j <= n; j++) {
- if (s[i - 1] == ')') {
- a[i][j] = a[i - 1][j + 1];
- continue;
- }
- if (s[i - 1] == '(') {
- if (j - 1 >= 0) {
- a[i][j] = a[i - 1][j - 1];
- }
- continue;
- }
- if (j - 1 >= 0) {
- a[i][j] = a[i - 1][j + 1] + a[i - 1][j - 1];
- }
- else {
- a[i][j] = a[i - 1][j + 1];
- }
- }
- }
- cout << a[n][0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement