C++ | 3D DP - Maintaining prev left & right used color
Code

# Code
```cpp []
class Solution {
public:
    #define ll long long
    ll dp[50001][4][4];
    ll find(int i,int lprev,int rprev,int n,vector<vector<int>>& cost)
    {
        if(i>=n/2)
           return 0;
        if(dp[i][lprev][rprev]!=-1)
           return dp[i][lprev][rprev];
        ll res=LONG_MAX;
        int j=n-1-i;
        for(int lc=1;lc<=3;lc++)
        {
            for(int rc=1;rc<=3;rc++)
            {
                if(lc!=rc && lc!=lprev && rc!=rprev)
                {
                    ll currCost=cost[i][lc-1]+cost[j][rc-1];
                    res=min(res,currCost+find(i+1,lc,rc,n,cost));
                }
            }
        } 
        return dp[i][lprev][rprev]=res;     
    }
    long long minCost(int n, vector<vector<int>>& cost) 
    {
        memset(dp,-1,sizeof(dp));
        return find(0,0,0,n,cost);
    }
};
```
['C++']