Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- #define MAXN 10000
- #define max(a, b) ((a) > (b) ? (a) : (b))
- int N;
- int P[MAXN], memo[MAXN];
- int dp(int u, int prec) {
- if(u >= N) return 0;
- if(memo[u] != -1) return memo[u];
- int yes = 0, no = dp(u+1, prec);
- if(P[u] < prec) yes = dp(u+1, P[u])+1;
- memo[u] = max(yes, no);
- return memo[u];
- }
- int main() {
- freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- scanf("%d", &N);
- for(int i = 0; i < N; i++) memo[i] = -1;
- for(int i = 0; i < N; i++) scanf("%d", P+i);
- dp(0, MAXN);
- printf("%d", *std::max_element(memo, memo+N));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement