-
Notifications
You must be signed in to change notification settings - Fork 1
/
248.cpp
63 lines (31 loc) · 707 Bytes
/
248.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("248.in", "r", stdin);
int n;
cin >> n;
vector<int> a(n);
int best = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
best = max(best, a[i]);
}
vector<vector<int>> dp(n, vector<int>(n, -1));
for (int len = 1; len <= n; len++) {
for (int l = 0; l + len - 1 < n; l++) {
int r = l + len - 1;
if (l == r) {
dp[l][r] = a[l];
continue;
}
for (int rr = l; rr < r; rr++) {
if (dp[l][rr] != -1 && dp[l][rr] == dp[rr + 1][r]) {
dp[l][r] = max(dp[l][r], dp[l][rr] + 1);
}
}
best = max(best, dp[l][r]);
}
}
freopen("248.out", "w", stdout);
cout << best << endl;
}