Javascript - DP
Code
# Code
```javascript []
/**
 * @param {number} n
 * @param {number[][]} cost
 * @return {number}
 */
var minCost = function (n, cost) {
  const half = n / 2;
  const dp = new Array(half)
    .fill()
    .map(() => new Array(3).fill().map(() => new Array(3).fill()));
  const combs = [
    [0, 1],
    [0, 2],
    [1, 0],
    [1, 2],
    [2, 0],
    [2, 1],
  ];

  return helper(0, -1, -1, cost, combs, dp, half);
};

function helper(idx, oi, oj, cost, combs, dp, half) {
  if (idx >= half) return 0;
  if (dp[idx][oi]?.[oj] !== undefined) return dp[idx][oi][oj];

  let minCost = Infinity;
  for (const [ni, nj] of combs) {
    if (ni === oi || nj === oj) continue;
    const curr = cost[idx][ni] + cost[cost.length - 1 - idx][nj];
    const next = helper(idx + 1, ni, nj, cost, combs, dp, half);
    minCost = Math.min(minCost, curr + next);
  }

  if (oi === -1) return minCost;
  return (dp[idx][oi][oj] = minCost);
}

```
['Dynamic Programming', 'JavaScript']