My code with out memozation:
#include<bits/stdc++.h>
#define F first;
#define S second;
#define PB push_back;
#define er erase;
#define MP make_pair;
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
typedef long long int ll;
using namespace std;
ll arr[100001],n;
ll solve(ll i,ll prev,ll dp[])
{
if(i==n)
{
return 0;
}
else
{
if(arr[i]>=prev)
{
return max(solve(i+1,prev=arr[i],dp)+1,solve(i+1,prev,dp));
}
else
{
return solve(i+1,prev,dp);
}
}
}
int main()
{
fastio;
ll prev=-INF;
cin>>n;
for(ll i=0;i<n;i++)
{
cin>>arr[i];
}
ll dp[n+1];
memset(dp,-1,sizeof(dp));
ll i=0;
cout<<solve(i,prev,dp)<<endl;
return 0;
}
How do i have to store the subproblem in array named dp?