-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
651.cpp
26 lines (26 loc) · 798 Bytes
/
651.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
__________________________________________________________________________________________________
class Solution {
public:
int maxA(int N) {
int res = N;
for (int i = 1; i < N - 2; ++i) {
res = max(res, maxA(i) * (N - 1 - i));
}
return res;
}
};
__________________________________________________________________________________________________
class Solution {
public:
int maxA(int N) {
vector<int> dp(N + 1, 0);
for (int i = 0; i <= N; ++i) {
dp[i] = i;
for (int j = 1; j < i - 2; ++j) {
dp[i] = max(dp[i], dp[j] * (i - j - 1));
}
}
return dp[N];
}
};
__________________________________________________________________________________________________