wants to know how to write code of longest increasing subsequence in top down approach?

Here is the code what i tried but only 2 or 3 test case pass i want to know the code for LIS in c++
http://leetcode.com/problems/longest-increasing-subsequence/

  here i wants to know top down approach of this question in c++
  
 int lis(vector<int>&nums,int i,int n,int prev,vector<int>& ls){
   if(i==n||n==0){
    return 0;
    }
     if(ls[i]!=-1){
      return 1 ;
      }


     lis(nums,i+1,n,prev,ls);
        if(nums[i]>prev){
          int  num=1+lis(nums,i+1,n,nums[i],ls);
    
           ls[num]=1;
          return num;
        }
         return 0;
     }

       class Solution {
       public:
        int lengthOfLIS(vector<int>& nums) {
        int  n=nums.size();
          int c;
          vector<int> ls(n+1,-1);
    
          lis(nums,0,n,INT_MIN,ls);
           for(int i=n;i>=0;i--){
          if(ls[i]!=-1){
            c=i;
             break;
          }
          else{
          c=0;
           }
            }
             if(nums.size()==0){
               return 0;
             }
            else{

         if(c==0){
       return 0;

           }
         else{
            return c;

Comments (1)