Simple memoization and for loop for valid combinations
Simple solution with memoization, no hard coded arrays, simple for loops to determine valid combinations.Code
Simple solution with memoization, no hard coded arrays, simple for loops to determine valid combinations.



# Code
```java []
class Solution {
    public long minCost(int n, int[][] cost) {
        long[][] memo = new long[3][3];
        for(int i=n/2-1;i>=0;i--){
            long[][] curMin = new long[3][3];
            for(int c1=0;c1<3;c1++) {
                for(int c2=0;c2<3;c2++){
                    if(c1==c2)
                    continue;
                    curMin[c1][c2] = cost[i][c1]+cost[n-1-i][c2]+getMin(c1, c2, memo);
                }
            }
            memo=curMin;
        }
        long res=Long.MAX_VALUE;
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(i==j)
                continue;
                res=Math.min(res, memo[i][j]);
            }
        }
        return res;
    }
    long getMin(int c1, int c2, long[][] memo){
        long min=Long.MAX_VALUE;
        for(int mc1=0;mc1<3;mc1++){
            for(int mc2=0;mc2<3;mc2++){
                if(mc1==mc2 || c1==mc1 || c2==mc2)
                continue;
                min=Math.min(min, memo[mc1][mc2]);
            }
        }
        return min;
    }
}
```
['Java']