diff --git a/cpp/2205/220511.cpp b/cpp/2205/220511.cpp new file mode 100644 index 0000000..42b6724 --- /dev/null +++ b/cpp/2205/220511.cpp @@ -0,0 +1,23 @@ +#include + +/** + * 1641. Count Sorted Vowel Strings + * + * Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted. + * A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet. + */ + +class Solution { +public: + static int countVowelStrings(int n) { + int ans[5]{1, 1, 1, 1, 1}; + while (--n) + ans[4] += (ans[3] += (ans[2] += ++ans[1])); + return ans[0] + ans[1] + ans[2] + ans[3] + ans[4]; + } +}; + +int main() { + std::printf("%d\n", Solution::countVowelStrings(33)); + return 0; +} diff --git a/cpp/2205/CMakeLists.txt b/cpp/2205/CMakeLists.txt index 52a555d..a7eb06f 100644 --- a/cpp/2205/CMakeLists.txt +++ b/cpp/2205/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2205) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2205 220511-CN.cpp) +ADD_EXECUTABLE(2205 220511.cpp)