def dp(self, A, K, target):
        """
        DP:
        jCi = v

        f[i][j][v] = f[i-1][j-1][v-A[j-1]] + f[i][j-1][v]

        f[i][j][v] means the way of selecting i elements from the first j elements so that their sum equals to v
        j is the scanning pointer
        you can either select A[j-1] or not select A[j-1]

        O(n^2 k)

        :param A:
        :param K:
        :param target:
        :return:
        """
        n = len(A)

        f = [[[0 for _ in xrange(target+1)] for _ in xrange(n+1)] for _ in xrange(K+1)]
        for ind, val in enumerate(A):
            if val <= target:
                for j in xrange(ind+1, n+1):  # non-trivial
                    f[1][j][val] = 1

        for i in xrange(2, K+1):
            for j in xrange(i, n+1):
                for v in xrange(1, target+1):
                    f[i][j][v] = 0
                    if v-A[j-1] >= 0:
                        f[i][j][v] += f[i-1][j-1][A[j-1]-v]
                    if j-1 >= i:
                        f[i][j][v] += f[i][j-1][v]

        return f[K][n][target]
dataset/ETHPy150Open algorhythms/LintCode/k Sum.py/Solution.dp/swapped operands of `-`