def numWays_MLE2(self, n, k):
        if n < 1:
            return 0

        F = [[[0 for _ in xrange(k)] for _ in xrange(k)] for _ in xrange(2)]
        EMPTY = 0

        for j0 in xrange(k):
            F[1][j0][EMPTY] = 1

        for i in xrange(2, n+1):
            for j0 in xrange(k):
                for j1 in xrange(k):
                    F[i%2][j0][j1] = 0

            for j0 in xrange(k):
                for j1 in xrange(k):
                    for j2 in xrange(k):
                        if i == 2:
                            F[i%2][j0][j1] = F[(i-1)%2][j1][EMPTY]

                        elif j1 == j2 and j0 != j1:
                            F[i%2][j0][j1] += F[(i-1)%2][j1][j2]
                        elif j1 != j2:
                            F[i%2][j0][j1] += F[(i-1)%2][j1][j2]

        ret = 0
        for j0 in xrange(k):
            for j1 in xrange(k):
                ret += F[n%2][j0][j1]

        return ret
DP
dataset/ETHPy150Open algorhythms/LeetCode/276 Paint Fence.py/Solution.numWays_MLE2