Simple Top Down recursive DP + bitmask.  Generate all valid combination first. 
Code

# Code
```cpp []
class Solution {
public:

    int m,n;
    int mod=1e9+7;
    int dp[1000][32][32];
    int dfs(int currow,int previgreen,int previblue,vector<pair<int,int>>& masks)
    {
        if(currow==n) return 1;
        if(dp[currow][previgreen][previblue]!=-1) return dp[currow][previgreen][previblue];
        long long ans=0;
        int previousred=previgreen^previblue;
        for(auto it:masks)
        {
            int tempgreen=it.first,tempblue=it.second;
            int tempred=tempgreen^tempblue;
            bool redok=true;
            for(int i=0;i<m;i++)
            {
                if(((previousred >> i) & 1)==0&&((tempred >> i)&1) == 0)
                {
                    redok=false;
                    break;
                }
            }
            if(currow==0||((tempgreen&previgreen)==0&&(tempblue&previblue)==0&&redok))
            {
                ans+=dfs(1+currow,tempgreen,tempblue,masks);
                ans%=mod;
            }
        }
        return dp[currow][previgreen][previblue]=ans;
    }

    void getmask(int indx,int isgreen,int isblue,int previous,vector<pair<int,int>>& masks)
    {
        if(indx==m)
        {
            masks.push_back({isgreen,isblue});
            return;
        }
        for(int i=0;i<3;i++)
        {
            if(i!=previous)
            {
                if(i==0) getmask(indx+1,isgreen,isblue,i,masks);//red
                else if(i==1) getmask(indx+1,isgreen|(1<<indx),isblue,i,masks);//green
                else getmask(indx+1,isgreen,isblue|(1<<indx),i,masks);//blue
            }
        }
    }

    int colorTheGrid(int mcol, int nrow) 
    {
        m=mcol;
        n=nrow;
        vector<pair<int,int>> masks;
        getmask(0,0,0,-1,masks);
        memset(dp,-1,sizeof(dp));
        return dfs(0,0,0,masks);
    }
};
```
['Dynamic Programming', 'Depth-First Search', 'Recursion', 'Memoization', 'Bitmask', 'C++']