Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #pragma GCC optimize("-Ofast")
- #pragma GCC optimize("-ffast-math")
- #pragma GCC optimize("-funroll-loops")
- #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
- #define ll long long
- #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- const int N = 2e6 + 5, M = 1e2 + 5;
- const double PI = acos(-1), EPS = 1e-6;
- const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
- const int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
- const long long MOD = 1e9 + 7, MOD2 = 998244353, OO = 1e18;
- int t = 1, n, a[M], ans, mem[M][M][M];
- int dp(int first, int mid, int i)
- {
- if (i == n + 1)return 0;
- int &ret = mem[first][mid][i];
- if (~ret)return ret;
- int c1 = dp(first, mid, i + 1), c2;
- if (first == 0)c2 = dp(i, 0, i + 1);
- else if (mid == 0)c2 = dp(first, i, i + 1);
- else c2 = (a[mid] > a[first] && a[mid] > a[i])
- + dp(mid, i, i + 1);
- return ret = max(c1, c2);
- }
- void solve()
- {
- memset(mem, -1, sizeof mem);
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- cin >> a[i];
- }
- cout << dp(0, 0, 1);
- return;
- }
- int main()
- {
- IO
- // cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement