C++|Easy DP Take | Non-Take Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(N*N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nint dp[1001][1001];\nint solve(int ind,int target,vector<int>&nums,int n){\n    if(target<0)\n    return -1e5;\n    if(target==0){\n        return 0;\n    }\n    if(ind==n)\n    return -1e5;\n    if(dp[ind][target]!=-1)\n    return dp[ind][target];\n    int nontake=solve(ind+1,target,nums,n);\n    int take=1+solve(ind+1,target-nums[ind],nums,n);\n    return dp[ind][target]=max(take,nontake);\n}\n    int lengthOfLongestSubsequence(vector<int>& nums, int target) {\n        int n=nums.size();\n        memset(dp,-1,sizeof(dp));\n        int ans=solve(0,target,nums,n);\n        if(ans>=-1e5 && ans<=-1e4)\n        return -1;\n        return ans;\n    }\n};\n```
['C++']