leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1220.cpp (575B)


      1 class Solution {
      2     static const int MOD = 1E9 + 7;
      3 
      4   public:
      5     int countVowelPermutation(int n) {
      6         long dp[5], pdp[5] = {1, 1, 1, 1, 1};
      7         for (int i = 1; i < n; i++) {
      8             dp[0] = (pdp[1] + pdp[2] + pdp[4]) % MOD;
      9             dp[1] = (pdp[0] + pdp[2]) % MOD;
     10             dp[2] = (pdp[1] + pdp[3]) % MOD;
     11             dp[3] = (pdp[2]) % MOD;
     12             dp[4] = (pdp[2] + pdp[3]) % MOD;
     13             swap(dp, pdp);
     14         }
     15         int res = 0;
     16         for (int i = 0; i < 5; i++)
     17             res = (res + pdp[i]) % MOD;
     18         return res;
     19     }
     20 };