Simple Pick and Not Pick solution Recursive DP
\n\n# Complexity\n- Time complexity:O(n * target)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n * target)\n Add your space complexity he
\n\n# Complexity\n- Time complexity:`O(n * target)`\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:`O(n * target)`\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int solve(int ind,int n, vector<int> &nums,int run,int target,vector<vector<int>> &dp){\n\n        if(run > target) return -1e6;\n        if(run == target) return 0;\n        if(ind == n){\n            if(run == target){\n                return 0;\n            }\n            return -1e6;\n        }\n        if(dp[ind][run] != -1) return dp[ind][run];\n        \n        int a = -1, b = -1;\n        //Picking This Value\n        a = solve(ind+1,n,nums,run+nums[ind],target,dp)+1;\n\n        //Not Picking This Value\n        b = solve(ind+1,n,nums,run,target,dp);\n        \n        return dp[ind][run] = max(a,b);\n    }\n    int lengthOfLongestSubsequence(vector<int>& nums, int target) {\n        int n = nums.size();\n        vector<vector<int>> dp(n,vector<int>(target,-1));\n        int ans = solve(0,n,nums,0,target,dp);\n        //Checking if our answer is negative then return -1\n        ans = ans < 0?-1:ans;\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'C++']