aboutsummaryrefslogtreecommitdiff
path: root/other/count_vowels_permutation.cpp
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-03-10 00:36:13 -0600
committerJack Sangdahl <[email protected]>2025-03-10 00:36:13 -0600
commit7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch)
treeeb7a24ee2067f92245c57bb118e85a1baf15df50 /other/count_vowels_permutation.cpp
parent5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff)
downloadleetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz
leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip
chore: move cpp and rust code to directoryHEADmaster
Diffstat (limited to 'other/count_vowels_permutation.cpp')
-rw-r--r--other/count_vowels_permutation.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/other/count_vowels_permutation.cpp b/other/count_vowels_permutation.cpp
new file mode 100644
index 0000000..807a1f4
--- /dev/null
+++ b/other/count_vowels_permutation.cpp
@@ -0,0 +1,30 @@
+#include "leetcode.h"
+class Solution {
+public:
+ int countVowelPermutation(int n) {
+ int ans = 0;
+ memo.resize(n + 1, vector<int>(5, -1));
+ for (int i = 0; i < 5; i++)
+ ans += dp(n, i), ans %= mod;
+ return ans;
+ }
+
+private:
+ int mod = 1e9 + 7;
+ vector<vector<int>> relation = {{1}, {0, 2}, {0, 1, 3, 4}, {2, 4}, {0}}, memo;
+ int dp(int n, int v) {
+ if (n == 1)
+ return 1;
+ if (memo[n][v] != -1)
+ return memo[n][v];
+ memo[n][v] = 0;
+ for (int &i : relation[v])
+ memo[n][v] += dp(n - 1, i), memo[n][v] %= mod;
+ return memo[n][v];
+ }
+};
+
+int main() {
+ Solution obj;
+ cout << obj.countVowelPermutation(1);
+}