Advertisement
Josif_tepe

Untitled

May 30th, 2024
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. class Solution{
  2.     public:
  3.     typedef long long ll;
  4.    
  5.     long long countWays(int n, ll k){
  6.    
  7.         vector<ll> dp(n + 1);
  8.         dp[1] = k;
  9.         dp[2] = (k * k);
  10.         const ll MOD = 1e9 + 7;
  11.         for(int i = 3; i <= n; i++) {
  12.             dp[i] = (((dp[i - 1] + dp[i - 2]) % MOD) * ((k - 1) % MOD)) % MOD;
  13.         }
  14.         return dp[n] % MOD;
  15.     }
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement