A781 | [USACO 2015 February Bronze]COW
来源USACO / 2015
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Bessie the cow has stumbled across an intriguing inscription carved into a large stone in the middle of her favorite grazing field. The text of the inscription appears to be from a cryptic ancient language involving an alphabet with only the three characters C, O, and W. Although Bessie cannot decipher the text, she does appreciate the fact that C, O, and W in sequence forms her favorite word, and she wonders how many times COW appears in the text.
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 inscription, please help Bessie count how many times COW appears.
INPUT FORMAT:
The first line of input consists of a single integer N <= 10^5. The second line contains of a string of N characters, where each character is either a C, O, or W.
OUTPUT FORMAT:
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.
母牛贝西在她最喜欢的牧场中间偶然发现了一块刻在大石头上的有趣的铭文。铭文的文字似乎来自一种神秘的古代语言,其中只有三个字母 $C$、$O$ 和 $W$。她想知道 $COW$在文本中出现了多少次。
贝西不介意其他字母穿插在 $COW$ 中,只要字母按正确的顺序出现即可。她也不介意如果不同的 $COW$ 共享一些字母。例如,$COW$ 在 $CWOW$ 中出现一次,在 $CCOW$ 中出现两次,在 $CCOWW$ 中出现八次。
请帮助贝西计算有多少次$COW$出现。
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 inscription, please help Bessie count how many times COW appears.
INPUT FORMAT:
The first line of input consists of a single integer N <= 10^5. The second line contains of a string of N characters, where each character is either a C, O, or W.
OUTPUT FORMAT:
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.
母牛贝西在她最喜欢的牧场中间偶然发现了一块刻在大石头上的有趣的铭文。铭文的文字似乎来自一种神秘的古代语言,其中只有三个字母 $C$、$O$ 和 $W$。她想知道 $COW$在文本中出现了多少次。
贝西不介意其他字母穿插在 $COW$ 中,只要字母按正确的顺序出现即可。她也不介意如果不同的 $COW$ 共享一些字母。例如,$COW$ 在 $CWOW$ 中出现一次,在 $CCOW$ 中出现两次,在 $CCOWW$ 中出现八次。
请帮助贝西计算有多少次$COW$出现。
输入格式
第一行输入包含一个整数 $N < = 10 ^ 5$。第二行包含一个由 $N$ 个字符组成的字符串,其中每个字符都是$C、 O$ 或 $W$。
输出格式
输出 $COW$ 作为输入字符串的子序列(不一定是连续的)出现的次数。
注意,答案可能非常大,所以一定要使用 $64$位整数 $(C++$ 中的“ $long long$”, $Java$ 中的“ $long$”)来进行计算。
注意,答案可能非常大,所以一定要使用 $64$位整数 $(C++$ 中的“ $long long$”, $Java$ 中的“ $long$”)来进行计算。
输入输出样例
输入 #1
6 COOWWW
输出 #1
6
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?