Advertisement
Ikmik

E.cpp

Dec 29th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #define FAST_ALLOCATOR_MEMORY 1e8
  2. #include "optimization.h"
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <unordered_map>
  6. #include <string>
  7. #include <vector>
  8. #include <queue>
  9. #include <set>
  10. #include <map>
  11. #include <cstring>
  12. using namespace std;
  13. char str[101];
  14. int a[101][101];
  15. map<char, char> rev;
  16. int c(int start, int len){
  17.     if(a[start][len]) return a[start][len];
  18.     if (len - start == 1) return 0;
  19.     int cnt = 0;
  20.     for (int i = start; i < start + len; i++)
  21.         for (int j = i + 1; j < start + len; j++){
  22.             if (rev[str[i]] == str[j]){
  23.                 cnt = max(cnt, c(i + 1, j - i - 1) + c(j + 1, start + len - j - 1) + 2);
  24.             }
  25.         }
  26.     a[start][len] = cnt;
  27.     return cnt;
  28. }
  29. int main()
  30. {
  31.     rev['('] = ')';
  32.     rev['['] = ']';
  33.     rev['{'] = '}';
  34.     freopen("erase.in", "r", stdin);
  35.     freopen("erase.out", "wt", stdout);
  36.     readWord(str);
  37.     int n = strlen(str);
  38.     int ans = c(0, n);
  39.     cout << ans << endl;
  40.     return 0;
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement