Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <numeric>
- #include "C:\Projects\optimization.h"
- #include <algorithm>
- using namespace std;
- using tp = uint32_t;
- int main() {
- #ifdef LOCAL
- freopen("out.txt", "w", stdout);
- freopen("in.txt", "r", stdin);
- #endif
- char buff[10001];
- readWord(buff);
- string s = buff;
- int n = s.size();
- if (n%2 != 0){
- cout<< 0;
- return 0;
- }
- s = ' ' + s;
- n++;
- vector<vector<int64_t>> dp (2,vector<int64_t>(n+1));
- dp[0][0] = 1;
- for(int i = 1; i < n; i++ ){
- for(int b = 0; b < n; b++){
- if(s[i] == '('){
- dp[i%2][b] = dp[(i+1)%2][b-1];
- }
- else if(s[i] == ')'){
- dp[i%2][b] = dp[(i+1)%2][b+1];
- }
- else {
- dp[i%2][b] = dp[(i+1)%2][b+1];
- if(b>0) {
- dp[i%2][b] += dp[(i+1)%2][b-1];
- }
- }
- dp[i%2][b] %= 1000000007;
- }
- }
- writeInt(dp[0][0]);
- }
Advertisement
Add Comment
Please, Sign In to add comment