EASY Solution || 0/1 Knapsack
Intuition\nKnapsack problem , dp\n\n# Approach\nThis is classic dp 0/1 knapsack problem.\n1. for every element we have two choices.\n   a. either take that elem
# Intuition\nKnapsack problem , dp\n\n# Approach\nThis is classic dp 0/1 knapsack problem.\n1. for every element we have two choices.\n   a. either take that element or\n   b. ignore that element.\n2. If our target becomes 0, means we have chosen correct subsequence \n \nSee my solution to understand better.\n\n\n# Code\n```\nclass Solution {\n    int[][] memo;\n    public int lengthOfLongestSubsequence(List<Integer> nums, int target) {\n        \n        memo=new int[nums.size()+1][target+1];\n        for(int[] arr:memo)Arrays.fill(arr,-1);\n\n        int ans= memoization(nums,0,target);\n\n        if(ans<=0)return -1;\n\n        return ans;\n    }\n    \n    //recursive\n    \n    public int recursive(List<Integer> list, int st, int target){\n        if(target==0)return 0;\n\n        if(target<0||st>=list.size())return Integer.MIN_VALUE+1001;\n        \n        int take=1+recursive(list,st+1,target-list.get(st));\n\n        int ignore=recursive(list,st+1,target);\n\n        return Math.max(take,ignore);\n    }\n    \n    //memoization\n    \n    public int memoization(List<Integer> list, int st, int target){\n\n        if(target==0)return 0;\n\n        if(target<0||st>=list.size())return Integer.MIN_VALUE+1001;\n\n        if(memo[st][target]!=-1)return memo[st][target];\n\n        int take=1+memoization(list,st+1,target-list.get(st));\n\n        int ignore=memoization(list,st+1,target);\n\n        return memo[st][target]=Math.max(take,ignore);\n    }\n}\n```
['Dynamic Programming', 'Memoization', 'Java']