Raslboyy

208

Sep 1st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     ifstream fin("input.txt");
  10.     ofstream fout("output.txt");
  11.  
  12.     string str; fin >> str;
  13.     int n = str.size();
  14.     str = ' ' + str;
  15.     vector<vector<int>> vec(n + 1, vector<int>(n + 1));
  16.     vec[0][0] = 1;
  17.     for (int i = 1; i <= n; i++)
  18.         for (int j = 0; j <= n; j++) {
  19.             if (j - 1 >= 0 && (str[i] == '(' || str[i] == '?'))
  20.                 vec[i][j] += vec[i - 1][j - 1];
  21.             if (j + 1 <= n && (str[i] == ')' || str[i] == '?'))
  22.                 vec[i][j] += vec[i - 1][j + 1];
  23.         }
  24.     fout << vec[n][0] << endl;
  25.  
  26.  
  27.     fin.close();
  28.     fout.close();
  29.     return 0;
  30. }
Add Comment
Please, Sign In to add comment