Recursion +  DP Solution || CPP
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int res;\n    int solve(int i, vector<int>& nums, int target , vector<vector<int>>&dp) {\n        if (target == 0) {\n            return 0;\n        }\n        if (i >= nums.size() || target < 0) {\n            return INT_MIN;\n        }\n        if(dp[i][target]!=-1){\n            return dp[i][target];\n        }\n        int take = 1 + solve(i+1,nums,target-nums[i],dp);\n        int not_take = solve(i + 1, nums, target,dp);\n\n        return dp[i][target] =  max(take, not_take);\n        \n    }\n\n    int lengthOfLongestSubsequence(vector<int>& nums, int target) {\n        vector<vector<int>>dp(nums.size()+1,vector<int>(target+1,-1));\n        res =  solve(0, nums, target, dp);\n        if(res<=0){\n            return -1;\n        }\n        return res;\n    }\n};\n\n```
['C++']