Bottom Up DP Solution || Tabulation || Beginner Friendly
IntuitionApproachComplexity
Time complexity:O(n∗3∗3)

Space complexity:O(n∗4∗4)
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*3*3)$$ 
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

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