Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- using namespace std;
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- string str; fin >> str;
- int n = str.size();
- str = ' ' + str;
- vector<vector<int>> vec(n + 1, vector<int>(n + 1));
- vec[0][0] = 1;
- for (int i = 1; i <= n; i++)
- for (int j = 0; j <= n; j++) {
- if (j - 1 >= 0 && (str[i] == '(' || str[i] == '?'))
- vec[i][j] += vec[i - 1][j - 1];
- if (j + 1 <= n && (str[i] == ')' || str[i] == '?'))
- vec[i][j] += vec[i - 1][j + 1];
- }
- fout << vec[n][0] << endl;
- fin.close();
- fout.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment