Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int INF = 2e9;
- const int maxn = 2002;
- vector<pair<int, int>> v;
- int dp[maxn];
- int rec(int at) {
- if(dp[at] != -1) {
- return dp[at];
- }
- int res = 1;
- for(int i = at + 1; i < v.size(); i++) {
- if(v[at].second <= v[i].second) {
- res = max(res, rec(i) + 1);
- }
- }
- return dp[at] = res;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- int t;
- cin >> t;
- while(t--) {
- v.clear();
- int n;
- cin >> n;
- vector<int> a(n), b(n);
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- for(int i = 0; i < n; i++) {
- cin >> b[i];
- v.push_back(make_pair(a[i], b[i]));
- }
- sort(v.begin(), v.end());
- memset(dp, -1, sizeof dp);
- int res = 0;
- for(int i = 0; i < n; i++) {
- res = max(res, rec(i));
- }
- cout << res << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement