Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
999 B
1
Indexable
Never
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'

#ifndef ONLINE_JUDGE
    #include "debug.h"
#else 
    #define deb(x...)
#endif

vector<int> dp;
int n;
vector<int> a;
map<vector<int>, int> m;
vector<int> vv;

int rec(int level) {
    if (level == -1) {
        return 0;
    }
    if (dp[level] != -1e9) {
        return dp[level];
    }
    int ans = 1;
    for (int i = 0; i < level; i++) {
        if (a[i] < a[level]) {
            ans = max(ans, 1 + rec(i));
        }
    }
    return dp[level] = ans;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    while(tt--) {
        cin >> n;
        dp.resize(n, -1e9);
        a.resize(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        rec(n - 1);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans = max(ans, rec(i));
        }
        deb(dp);
    }
    return 0;
}
Leave a Comment