Skip to content

Latest commit

 

History

History
23 lines (20 loc) · 639 Bytes

File metadata and controls

23 lines (20 loc) · 639 Bytes
	int maxSumIS(int arr[], int n)  
	{  
	    vector<int>dp(n,0);             //ith index of dp vector contain the max sum in increasing sub
	    int ans=arr[0];
	    dp[0]=arr[0];
	    
	    for(int i=1;i<n;i++)
	    {
	        for(int j=i-1;j>=0;j--)
	        {
	            if(arr[j]<arr[i])           //as strictly increasing
	                dp[i]=max(dp[i],dp[j]);
	        }
	        
	        dp[i] +=arr[i];
	        ans=max(ans,dp[i]);
	    }
	    return ans;
	}