Simple Memoization Code
\nJava []\nclass Solution {\n    List<Integer> nums;\n    public int lengthOfLongestSubsequence(List<Integer> nums, int target) {\n        int n=nums.size();\n 
\n```Java []\nclass Solution {\n    List<Integer> nums;\n    public int lengthOfLongestSubsequence(List<Integer> nums, int target) {\n        int n=nums.size();\n        Integer dp[][]=new Integer[n][target];\n        this.nums=nums;\n        return f(dp, 0, 0, n, target);\n    }\n    private int f(Integer[][] dp, int curr, int ind, int n, int t) {\n        if(curr==t) return 0;\n        if(curr>t || (ind==n && curr<t)) return -1;\n        if(dp[ind][curr]!=null) return dp[ind][curr];\n        int v;\n        return dp[ind][curr]=Math.max((v=f(dp, curr+nums.get(ind), ind+1, n, t))==-1?-1:v+1,\n                                      f(dp, curr, ind+1, n, t));\n    }\n}\n```
['Dynamic Programming', 'Memoization', 'Java']