Super-efficient dp solution
Not my code but someone submitted this on China server and it seems pretty cool
Not my code but someone submitted this on China server and it seems pretty cool

```cpp []
class Solution {
public:
    long long minCost(int n, vector<vector<int>>& cost) {
        long long ab = 0, ac = 0, ba = 0, bc = 0, ca = 0, cb = 0;
        for (int i = 0; i * 2 < n; ++i) {
            auto& va = cost[i];
            auto& vb = cost[n - i - 1];

            long long ab_ = va[0] + vb[1] + min(bc, min(ba, ca));
            long long ac_ = va[0] + vb[2] + min(ba, min(ca, cb));
            long long ba_ = va[1] + vb[0] + min(ab, min(ac, cb));
            long long bc_ = va[1] + vb[2] + min(ab, min(ca, cb));
            long long ca_ = va[2] + vb[0] + min(ab, min(ac, bc));
            long long cb_ = va[2] + vb[1] + min(ac, min(ba, bc));

            ab = ab_;
            ac = ac_;
            ba = ba_;
            bc = bc_;
            ca = ca_;
            cb = cb_;
        }
        return min(ab, min(ac, min(ba, min(bc, min(ca, cb)))));
    }
};
```
['C++']