Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <cmath>
- using namespace std;
- const int maxn = 100;
- int n, arr[maxn];
- int dp[maxn];
- int rec(int at) {
- if(dp[at] != -1) {
- return dp[at];
- }
- int res = 0;
- for(int i = at + 1; i < n; i++) {
- if(arr[at] < arr[i]) {
- res = max(res, rec(i) + 1);
- }
- }
- return dp[at] = res;
- }
- int main() {
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- for(int i = 0; i < maxn; i++) {
- dp[i] = -1;
- }
- int res = 0;
- for(int i = 0; i < n; i++) {
- res = max(res, rec(i) + 1);
- }
- cout << res << endl;
- return 0;
- }
- // fib(4) = fib(3) + fib(2) = 2 + 1 = 3
- // fib(3) = fib(2) + fib(1) = 1 + 1 = 2
- // fib(2) = 1
- // fib(1) = 1
- // fib(2) = 1
- // 7 7 7 7 7 7 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement