DP Tabulation Approach
IntuitionDP - TabulationComplexity

Time complexity: O(N*144)


Space complexity: O(N*16)

Code
# Intuition
DP - Tabulation

# Complexity
- Time complexity: O(N*144)

- Space complexity: O(N*16)

# Code
```cpp []
class Solution {
public:
    long long dp[(long long)1e5 + 5][4][4];
    long long minCost(int n, vector<vector<int>>& c) {
        for(int i=0; i<n; i++){
            for(int j=0; j<=3; j++){
                for(int k=0; k<=3; k++){
                    if(i >= n/2){
                        dp[i][j][k] = 0;
                    } else {
                        dp[i][j][k] = LLONG_MAX;
                    }
                }
            }
        }
        long long f_res = LLONG_MAX;
        for(int i=(n-2)/2; i>=0; i--){
            for(int l=0; l<4; l++){
                for(int m=0; m<4; m++){
                    long long result = LLONG_MAX;
                    for(int j=0; j<3; j++){
                        for(int k=0; k<3; k++){
                            if(j!=k && j!=l && k!= m){
                                result = min(result, c[i][j] + c[n-i-1][k] + dp[i+1][j][k]);
                            }
                        }   
                    }
                    dp[i][l][m] = min(dp[i][l][m], result);
                    if(i == 0){
                        f_res = min(f_res, dp[i][l][m]);
                    }
                }   
            }
        }
        return f_res;
    }
};
```
['C++']