nikunjsoni

651

Jun 11th, 2021
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxA(int n) {
  4.         int dp[51];
  5.         dp[0] = 0;
  6.         dp[1] = 1;
  7.         dp[2] = 2;
  8.         for(int i=3; i<=n; i++){
  9.             dp[i] = i;
  10.             for(int j=1; j<i; j++){
  11.                 dp[i] = max(dp[i], (i-j-1)*dp[j]);
  12.             }
  13.         }
  14.         return dp[n];
  15.     }
  16. };
  17.  
  18. ---------------------
  19.  
  20. class Solution {
  21. public:
  22.     int maxA(int n) {
  23.         int dp[51];
  24.         for(int i=0; i<=6; i++)
  25.             dp[i] = i;
  26.         for(int i=7; i<=n; i++){
  27.             dp[i] = i;
  28.             dp[i] = max({dp[i], dp[i-4]*3, dp[i-5]*4});
  29.         }
  30.         return dp[n];
  31.     }
  32. };
Advertisement
Add Comment
Please, Sign In to add comment