[C++][Bottom up DP]
Code


# Code
```cpp []
class Solution {
public:
    long long minCost(int n, vector<vector<int>>& cost) {
        vector<vector<vector<long long>>> dp(n/2, vector<vector<long long>> (3, vector<long long>(3, LONG_MAX)));
        for (int i=0;i<3;i++){
            for (int j=0;j<3;j++){
                if (i!=j) {
                    dp[0][i][j] = cost[0][i] + cost.back()[j];
                }
            }
        }
        for (int i=1;i<n/2;i++){
            for (int j=0;j<3;j++){
                for (int k=0;k<3;k++){
                    if (j!=k){
                        for (int l=0;l<3;l++){
                            for(int m=0;m<3;m++){
                                if (l==j || m==k || dp[i-1][l][m]==LONG_MAX) continue;
                                dp[i][j][k] = min(dp[i][j][k], cost[i][j]+cost[n-i-1][k]+dp[i-1][l][m]);
                            }
                        }
                    }
                }
            }
        }
        long long ans = LONG_MAX;
        for (int i=0;i<3;i++){
            for (int j=0;j<3;j++){
                ans = min(ans, dp.back()[i][j]);
            }
        }
        return ans;
    }
};
```
['C++']