Python using cache(DP)
Intuition\nclassic dp on subsequence \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:\n Add your time comple
# Intuition\nclassic dp on subsequence \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        @cache\n        def solve(i,val):\n            if val==target:\n                return 0\n            if i>=len(nums) or val>target:\n                return -1001\n            \n            return max(1+solve(i+1,val+nums[i]),solve(i+1,val))\n            \n            \n        \n        a=solve(0,0)\n        solve.clear_cache()\n        if a>0:\n            return a\n        return -1\n```
['Python3']