DP || Recursion + Memoization || Easy C++ ✔✔
\n# Complexity\n- Time complexity:O(N * T)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(N * T)\n Add your space complexity here, e.g. O(n
\n# Complexity\n- Time complexity:O(N * T)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N * T)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n     int dp[1005][1005];\n    int fun(vector<int> &arr,int t,int i)\n    {\n        if(t==0) return 0;\n        if(i>=arr.size()) return -1*1e5;\n        \n        if(dp[i][t]!=-1) return dp[i][t];\n        \n        if(t>=arr[i])\n        return dp[i][t] = max(1+fun(arr,t-arr[i],i+1),fun(arr,t,i+1));\n        \n        return dp[i][t] = fun(arr,t,i+1);\n    }\n    int lengthOfLongestSubsequence(vector<int>& arr, int t) {\n        \n        memset(dp,-1,sizeof(dp));\n        int ans = fun(arr,t,0);\n        return ans<0 ? -1 :ans;    \n    }\n};\n```
['Dynamic Programming', 'C++']