kolbka_

Untitled

Dec 10th, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <numeric>
  5. #include "C:\Projects\optimization.h"
  6. #include <algorithm>
  7. using namespace std;
  8. using tp = uint32_t;
  9. int main() {
  10. #ifdef LOCAL
  11. freopen("out.txt", "w", stdout);
  12. freopen("in.txt", "r", stdin);
  13. #endif
  14. char buff[10001];
  15. readWord(buff);
  16. string s = buff;
  17. int n = s.size();
  18. if (n%2 != 0){
  19. cout<< 0;
  20. return 0;
  21. }
  22. s = ' ' + s;
  23. n++;
  24. vector<vector<int64_t>> dp (2,vector<int64_t>(n+1));
  25. dp[0][0] = 1;
  26. for(int i = 1; i < n; i++ ){
  27. for(int b = 0; b < n; b++){
  28. if(s[i] == '('){
  29. dp[i%2][b] = dp[(i+1)%2][b-1];
  30. }
  31. else if(s[i] == ')'){
  32. dp[i%2][b] = dp[(i+1)%2][b+1];
  33. }
  34. else {
  35. dp[i%2][b] = dp[(i+1)%2][b+1];
  36. if(b>0) {
  37. dp[i%2][b] += dp[(i+1)%2][b-1];
  38. }
  39.  
  40. }
  41.  
  42. dp[i%2][b] %= 1000000007;
  43.  
  44. }
  45.  
  46. }
  47. writeInt(dp[0][0]);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment