Using DP(Memoization)
Code
 
# Code
```cpp []
class Solution {
public:
    long long f(int i,int j,int prev1,int prev2,vector<vector<int>>& cost,int n,vector<vector<vector<long long>>>& dp){
       if(i > j) return 0;
        if(dp[i][prev1][prev2] != -1 ) return dp[i][prev1][prev2];
     long long ans = LLONG_MAX;
        for(int k=0;k<3;k++){
             for(int x=0;x<3;x++){
                  if(x != k && prev1-1 != k && prev2-1 != x){
                        ans = min(ans,cost[i][k]+cost[j][x] + f(i+1,j-1,k+1,x+1,cost,n,dp));
                  }
             }
        }
        return dp[i][prev1][prev2]= ans;
    }
    long long minCost(int n, vector<vector<int>>& cost) {
        int s = n / 2;
          vector<vector<vector<long long>>> dp(s+1, vector<vector<long long>>(4, vector<long long>(4, -1)));
         return f(0,n-1,0,0,cost,n,dp);
    }
};
```
['Dynamic Programming', 'Memoization', 'C++']