This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n;
int h[100005];
int t[100005];
int dp[5005][5005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
cin >> t[i];
}
for (int i = 0; i < n; i++) {
dp[i][i] = (h[i] == t[i] ? 1 : 0);
}
for (int d = 1; d < n; d++) {
for (int i = 0; i + d < n; i++) {
dp[i][i+d] = 0;
for (int j = i; j < i + d; j++) {
dp[i][i+d] = max(dp[i][i+d], dp[i][j] + dp[j+1][i+d]);
}
int maxx = 0;
for (int j = i; j <= i + d; j++) {
maxx = max(maxx, h[j]);
}
int cnt = 0;
for (int j = i; j <= i + d; j++) {
if (t[j] == maxx) {
cnt++;
}
}
dp[i][i+d] = max(dp[i][i+d], cnt);
}
}
cout << dp[0][n-1] << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |