O(nk) Time Complexity & O(k) Space Complexity
Complexity\n- Time complexity:\nO(nk)\n\n- Space complexity:\nO(k)\n\n# Code\n\nclass Solution {\npublic:\n    static constexpr int mod = 1e9 + 7;\n\n    static
# Complexity\n- Time complexity:\n$$O(nk)$$\n\n- Space complexity:\n$$O(k)$$\n\n# Code\n```\nclass Solution {\npublic:\n    static constexpr int mod = 1e9 + 7;\n\n    static int sumOfPower(const std::vector<int>& nums, const int k) {\n        const int n = nums.size();\n        std::vector<int> take(k + 1, 0);\n        std::vector<int> no_take(k + 1, 0);\n        no_take[0] = 1;\n        for (auto num : nums)\n            for (int i = k; i >= 0; --i) {\n                int nt = (take[i] + no_take[i]) % mod;\n                int t = nt;\n                if (i >= num) {\n                    t += (take[i - num] + no_take[i - num]) % mod;\n                    t %= mod;\n                }\n                take[i] = t;\n                no_take[i] = nt;\n            }\n        return (take.back() + no_take.back()) % mod;\n    }\n};\n```
['C++']