The simple codes using 0-1 knapsack.
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```\nclass Solution:\n    def lengthOfLongestSubsequence(self, nums: List[int], target: int) -> int:\n        #\u601D\u8DEF\uFF1A0-1\u80CC\u5305\uFF0C\u4EF7\u503C\u7B49\u4E8E\u76EE\u6807\u503C\u7684\u60C5\u51B5\u4E0B\u6700\u5927\u6570\u91CF\n        #\u7528\u9012\u5F52\u901A\u4E0D\u8FC7\uFF0C\u8D85\u65F6\u4E86\n        #\u4F18\u5316\u7A7A\u95F4\uFF0C\u53EA\u75282\u4E2A\u6570\u7EC4\n        #\u5728\u4F18\u5316\u7A7A\u95F4\uFF0C\u53EA\u75281\u4E2A\u6570\u7EC4\n        n = len(nums)\n        f = [-inf]*(target+1)\n        f[0] = 0\n        for x in nums:\n            for c in range(target, x-1, -1):\n                if c >= x:\n                    f[c] = max(f[c], f[c-x]+1)\n        ans = f[target]\n        return ans if ans > -inf else -1\n\n```
['Python3']