Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int maxA(int n) {
- int dp[51];
- dp[0] = 0;
- dp[1] = 1;
- dp[2] = 2;
- for(int i=3; i<=n; i++){
- dp[i] = i;
- for(int j=1; j<i; j++){
- dp[i] = max(dp[i], (i-j-1)*dp[j]);
- }
- }
- return dp[n];
- }
- };
- ---------------------
- class Solution {
- public:
- int maxA(int n) {
- int dp[51];
- for(int i=0; i<=6; i++)
- dp[i] = i;
- for(int i=7; i<=n; i++){
- dp[i] = i;
- dp[i] = max({dp[i], dp[i-4]*3, dp[i-5]*4});
- }
- return dp[n];
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment