Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- #include <string>
- #include <cstdlib>
- #include <vector>
- #include <queue>
- #include <set>
- #include <map>
- #include <cstdio>
- #include <iomanip>
- #define SWS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define pb push_back
- #define ppb pop_back
- #define ft first
- #define sd second
- #define read freopen("prices.in", "r", stdin)
- #define write freopen("prices.out", "w", stdout)
- #define files read; write
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pii;
- const int Z = (int)3e3 + 228;
- const int N = (int)3e5 + 228;
- const int MOD = (int)1e9 + 7;
- const int INF = (int) 1e9 + 228;
- int dp[111][111];
- int main()
- {
- SWS;
- //files;
- string s;
- cin >> s;
- int n = s.length();
- for (int i = 0; i < n; i++)
- dp[i][i] = 1;
- for (int len = 2; len <= n; len++)
- for (int i = 0; i < n; i++)
- {
- int l = i, r = i + len - 1;
- if (r >= n) break;
- if (len == 2 && s[l] == '(' && s[r] == ')')
- {
- dp[l][r] = 0;
- continue;
- }
- dp[l][r] = INF;
- for (int k = l; k < r; k++)
- dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r]);
- if (s[l] == '(' && s[r] == ')') dp[l][r] = min(dp[l][r], dp[l + 1][r - 1]);
- }
- cout << dp[0][n - 1];
- return 0;
- }
- //()x)y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement