Take Not_take DP || DP on subsequences || Recursion || Memoization || Tabulation || Beats 74%
Intuition\n Describe your first thoughts on how to solve this problem. \nAs the problem statement talks about subsequence so instantly my mind thought of a 2-D 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs the problem statement talks about subsequence so instantly my mind thought of a 2-D dp solution.\n\nFirst we need to take an ind varibale for traversing the array nums and t variable to check whether the sum of the elements in the subsequences which we have taken has become equal to the given target or not.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n Okay it\'s a no brainer when (ind==n) && (t==target) we would     return 0;\n\nand if (ind==n) && (t!=target) then we will return -1e8;\n\nand if(t>target)then also we will return -1e8;\n\n this happens because if we reach the end of the array and still  we don\'t have the sum of the subsequence equal to target,then we cannot consider its length so to not consider it, we add a big negative value so it doesn\'t affect our answer.\n\nif at some point of time if t becomes greater then the target value then in that case we cannot consider the length so we will follow the same procedure. \n\nnow the conditions are as follows if we consider taking the element\nnums[ind] we would add into the sum "t" and then we will increase the ind by 1,even if we dont take the index we would still increase the ind by 1.\n\nIn the end take the max of both the elements\n\nif it is less than or equal to 0 then return -1;\nelse return the function ();\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n      O(N*Target)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n      O(N*Target)\n# Code\n```\nclass Solution {\npublic:\n    int ans(int ind,int t,vector<int>&nums,vector<vector<int>>&dp,int n,int target){\n        if(ind==n){\n            if(t==target){\n               return 0;\n            }\n            else{\n               return -1e6;\n            }\n        }\n        if(t>target){\n            return -1e6;\n        }\n        if(dp[ind][t]!=-1){\n            return dp[ind][t];\n        }\n        int take=1+ans(ind+1,t+nums[ind],nums,dp,n,target);\n        int not_take=0+ans(ind+1,t,nums,dp,n,target);\n        return dp[ind][t]=max(take,not_take);\n    }\n    int lengthOfLongestSubsequence(vector<int>& nums, int target) {\n        int n=nums.size();\n        vector<vector<int>>dp(n+1,vector<int>(target+1,0));\n        for(int t=1;t<target;t++){\n            dp[n][t]=-1e6;\n        }\n        for(int i=n-1;i>=0;i--){\n            for(int j=target;j>=0;j--){\n               int take=-1e6;\n               if((j+nums[i])<=target){\n                 take=1+dp[i+1][j+nums[i]];\n               }\n               int not_take=0+dp[i+1][j];\n               dp[i][j]=max(take,not_take);\n            }\n        }\n        if(dp[0][0]<=0){\n            return -1;\n        }\n        return dp[0][0];\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']