Recursve dp ... easy to understand


#1

int dp[1001][10001];
int recur(int x,int y,vector<vector > &a)
{
if(x>=a.size()) return 0;
if(dp[x][y]!=-1) return dp[x][y];
if(a[x][0]>y) return dp[x][y]=max(1+recur(x+1,a[x][1],a),recur(x+1,y,a));
else return dp[x][y]=recur(x+1,y,a);
}
int Solution::solve(vector<vector > &A)
{
for(int i=0;i<1001;i++) for(int j=0;j<=10000;j++) dp[i][j]=-1;
return recur(0,0,A);
}