2.
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
int n=nums.size();
int ret=0;
vector<int>memo(n);
for(int i=0;i<n;i++)
{
ret=max(ret,dfs(i,nums,memo));
}
return ret;
}
int dfs(int pos,vector<int>&nums,vector<int>&memo)
{
if(memo[pos]!=0)
{
return memo[pos];
}
int count=1;
for(int i=pos+1;i<nums.size();i++)
{
if(nums[i]>nums[pos])
{
count=max(count,dfs(i,nums,memo)+1);
}
}
memo[pos]=count;
return memo[pos];
}
};