Advertisement
nikunjsoni

1220

Jun 15th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int countVowelPermutation(int n) {
  4.         long long mod=int(1e9)+7;
  5.         vector<long long> dp(5, 1), dp1(5);
  6.        
  7.         //a:0, e:1, i:2, o:3, u:4
  8.         for(int i=1; i<n; i++){
  9.             dp1[0] = (dp[1]+dp[2]+dp[4])%mod;
  10.             dp1[1] = (dp[2]+dp[0])%mod;
  11.             dp1[2] = (dp[1]+dp[3])%mod;
  12.             dp1[3] = (dp[2])%mod;
  13.             dp1[4] = (dp[3]+dp[2])%mod;
  14.             swap(dp, dp1);
  15.         }
  16.         return (dp[0]+dp[1]+dp[2]+dp[3]+dp[4])%mod;
  17.     }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement