奶牛贝茜在她最喜欢的牧场中发现了一块石碑,上面刻有神秘的碑文。
碑文的文字似乎来自一种神秘的古代语言,可看作一个只包含 C,O,W 三种字符的字符串。
尽管贝茜无法解密该文字,但是她很欣赏 C,O,W 按顺序构成她最喜欢的单词 COW。
她想知道 COW 在碑文中一共出现了多少次。
她不介意 C,O,W 之间是否存在其他字符,只要这三个字符按正确的顺序出现即可。
她也不介意多个不同的 COW 是否共享了一些字符。
例如,COW 在 CWOW 中只出现一次,在 CCOW 中出现两次,在 CCOOWW 中出现八次。
给定碑文中的文字,请帮助贝茜计算 COW 出现的次数。
第一行包含 N。
第二行包含一个长度为 N 的字符串,其中只包含字符 C,O,W。
输出给定字符串中 COW 作为子序列(不一定连续)的出现次数。
1≤N≤105
6 COOWWW
6
Bessie the cow has stumbled across an intriguing insc
Bessie doesn't mind if there are other characters interspersed within COW, only that the characters appear in the correct order. She also doesn't mind if different occurrences of COW share some letters. For instance, COW appears once in CWOW, twice in CCOW, and eight times in CCOOWW.
Given the text of the insc
Output the number of times COW appears as a subsequence, not necessarily contiguous, of the input string.
Note that the answer can be very large, so make sure to use 64 bit integers ("long long" in C++, "long" in Java) to do your calculations.
6
COOWWW
6