Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

class Solution { public: int numWays(int n, int k) { vector<int>dp(n + 1); dp[0] = 0, dp[1] = k, dp[2] = k * k; for(int i = 3; i <= n; i++) dp[i] = (dp[i - 2] + dp[i - 1]) * (k - 1); return dp[n]; } };

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.