easy dp c++
Intuition\ncase 1-when you multiply a element by -1 then you have only one option on next element to multiply it by 1(continue in same subarray or switch the su
# Intuition\ncase 1-when you multiply a element by -1 then you have only one option on next element to multiply it by 1(continue in same subarray or switch the subarray).\n\n\ncase 2-when you multiply a element by 1 then you have 2 options:-\na-multiply by 1 (means swith the subarray).\nb-multiply by -1 (means continue in same subarray).\n\n\n\n\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(2*N);\n\n- Space complexity:\nO(2*N);\n\n# Code\n```\n#define ll long long\nclass Solution {\n    ll n;\n    ll dp[100001][2];\n    ll solve(ll ind,vector<int>&nums,ll lst){\n        if(ind==n)return 0;\n        if(dp[ind][lst]!=-1)return dp[ind][lst];\n        ll ans=-1e15;\n        if(lst==0){\n            ans=max(ans,nums[ind]+solve(ind+1,nums,1));\n        }else{\n            ans=max(ans,-1*nums[ind]+solve(ind+1,nums,0));\n            ans=max(ans,nums[ind]+solve(ind+1,nums,1));\n        }\n        return dp[ind][lst]=ans;\n    }\npublic:\n    long long maximumTotalCost(vector<int>& nums) {\n        memset(dp,-1,sizeof(dp));\n        n=nums.size();\n        return solve(0,nums,0);\n    }\n};\n```
['C++']