3-D DP solution 
IntuitionApproachComplexity
Time complexity:O(n)

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
#include<bits/stdc++.h>
#define ll long long 

class Solution {
public:
    ll checkDP(int ind, int top, int bottom, int n, vector<vector<int>>& cost,
               vector<vector<vector<ll>>>& DP) {
        if (ind >= n / 2)
            return 0;

        if (DP[ind][top][bottom] != -1)
            return DP[ind][top][bottom];

        ll mini = LLONG_MAX;
        for (int i = 0; i < 3; i++) {
            if (i != top) {
                for (int j = 0; j < 3; j++) {
                    if (j != i && j != bottom) {
                        mini = min(mini, cost[ind][i] + cost[n - ind - 1][j] +
                                   checkDP(ind + 1, i, j, n, cost, DP));
                    }
                }
            }
        }

        return DP[ind][top][bottom] = mini;
    }

    long long minCost(int n, vector<vector<int>>& cost) {
        vector<vector<vector<ll>>> DP(n, vector<vector<ll>>(4, vector<ll>(4, -1)));
        return checkDP(0, 3, 3, n, cost, DP);
    }
};

```
['C++']