C++ top down approach


#1
class Solution {
public:
    bool dynamic(const string& A, const string& B, int m, int n, vector<vector<int>>& aux){
        if(m<=0 && n<=0)
            return true;
        if(n<=0)
            return false;
        if(aux[m][n]!=-1)
            return aux[m][n];
        bool ans=false;
        if((m>0 && A[m-1]==B[n-1] )|| B[n-1]=='.'){
            if(m>0)
                ans=dynamic(A, B, m-1, n-1, aux);
        }
        else if(B[n-1]=='*'){
            ans=dynamic(A, B, m, n-2, aux);
            if((m>0 && A[m-1]==B[n-2]) || B[n-2]=='.')
                if(m>0)
                    ans= ans || dynamic(A, B, m-1, n, aux);
        }
        aux[m][n]=ans;
        return ans;
    }

    bool isMatch(string A, string B) {
        int m=A.size(), n=B.size();
        vector<vector<int>> aux(m+1, vector<int>(n+1, -1));
        return dynamic(A, B, m, n, aux);
    }
};

#2

This is not top down,its bottom up


#3

It is top down.

In top down Each subsystem is then refined in yet greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements. A top-down model is often specified with the assistance of “black boxes”, which makes it easier to manipulate.

In a bottom-up approach the individual base elements of the system are first specified in great detail. These elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is formed.


#4

lol it is top down dude