add: 220511 [cpp]

This commit is contained in:
Eat-Swap 2022-05-12 01:06:08 +08:00
parent b923827fd7
commit 292c603644
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
2 changed files with 24 additions and 1 deletions

23
cpp/2205/220511.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <cstdio>
/**
* 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;
}

View File

@ -3,4 +3,4 @@ PROJECT(2205)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2205 220511-CN.cpp)
ADD_EXECUTABLE(2205 220511.cpp)