:: Kotlin :: DP ( Skip Or Take )
Code\n\nclass Solution {\n    val MOD = 1_000_000_007\n\n    fun sumOfPower(nums: IntArray, k: Int): Int {\n        val n = nums.size\n        val cache = HashM
# Code\n```\nclass Solution {\n    val MOD = 1_000_000_007\n\n    fun sumOfPower(nums: IntArray, k: Int): Int {\n        val n = nums.size\n        val cache = HashMap<Triple<Int, Int, Int>, Int>()\n\n        val powers = IntArray(101){1}\n        for (i in 1 .. 100) {\n            powers[i] = (powers[i - 1] * 2) % MOD\n        }\n\n        fun helper(index: Int, sum: Int, count: Int): Int{\n            val key = Triple(index, sum, count)\n            if (cache.containsKey(key)) return cache.getOrDefault(key, 0)\n\n            if (sum == k) {\n                return powers[n - count]\n            }\n            if (sum > k) return 0\n            if (index == n) return 0\n            var result = 0\n\n            // take\n            result += helper(index + 1, sum + nums[index], count + 1)\n            result %= MOD\n\n            // skip\n            result += helper(index + 1, sum, count)\n            result %= MOD\n\n            cache.put(key, result)\n            return result\n        }\n\n        return helper(0, 0, 0)\n    }\n}\n```
['Kotlin']