Runtime erro,need help using MCM


#1

vector<vector>t(101,vector(1001,-1));
int solv(int A,int B){

if(B==0||B==1)
    return B;
if(A==1)
    return B;
if(t[A][B]!=-1)
    return t[A][B];
int res=INT_MAX;
for(int i=1;i<=B;i++){
    int low,high;
    if(t[A-1][i-1]!=-1)
        low=t[A-1][i-1];
    else{
        t[A-1][i-1]=solv(A-1,i-1);
        low=t[A-1][i-1];
    }
    if(t[A][B-i]!=-1)
        high=t[A][B-i];
    else{
        t[A][B-i]=solv(A,B-i);
        high=t[A][B-i];
    }
    int temp=1+max(low,high);
    res=min(res,temp);
}
return res;

}
int Solution::solve(int A, int B) {
for(int i=0;i<=A;i++)
for(int j=0;j<=B;j++)
t[A][B]=-1;
return solv(A,B);
}


#2

your both else statements are wrong.you are not storing them ,you are just finding the value of low and high. your statements should be like;
low =solv(A-1,i-1);
t[A-1][i-1]=low;
high =solv(A,B-i);
t[A][B-i]=high;


#3

you are wrong bro,careful look at the statements
t[A-1][i-1]=solv(A-1,i-1);
low=t[A-1][i-1];
its the same,in the first statement value is being saved