Most Simple way to Understated
\n\n# Approach\nrecursion : Take Not-take\n\n# Complexity\n- Time complexity : O(N)2 = O(N);\n\n- Space complexity:\nO(n2)\n\n# Code\n```\nclass Solution {\npub
\n\n# Approach\nrecursion : Take Not-take\n\n# Complexity\n- Time complexity : O(N)*2 = O(N);\n\n- Space complexity:\nO(n*2)\n\n# Code\n```\nclass Solution {\npublic:\n    long long int helper(vector<int>& nums, int i, int state, vector<vector<long long int>>& dp) {\n        if (i >= nums.size())\n            return 0;\n\n        if (dp[i][state] != -1)\n            return dp[i][state];\n\n        long long int includ = -1e16;\n        long long int exclud = -1e16;\n\n        if (state == 0) {\n            includ = -1 * (nums[i]) + helper(nums, i + 1, 1, dp);\n        } else if (state == 1) {\n            includ =  (nums[i]) + helper(nums, i + 1, 0, dp);\n        }\n\n        exclud = nums[i] + helper(nums, i + 1, 0, dp);\n\n        return dp[i][state] = max(includ, exclud);\n    }\n\n    long long int maximumTotalCost(vector<int>& nums) {\n        if (nums.size() <= 1)\n            return nums[0];\n\n        vector<vector<long long int>> dp(nums.size() + 1, vector<long long int>(2, -1));\n\n        long long int temp1 = 0;\n        temp1 = helper(nums, 0, 1, dp);\n\n        return temp1;\n    }\n};\n
['C++']