A10811 | Bear and Company
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible.
Limak has a string $s$ that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string "ABBC" into "BABC" or "ABCB" in one move.
Limak wants to obtain a string without a substring "VK" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string $s$ .
What is the minimum possible number of moves Limak can do?
Limak has a string $s$ that consists of uppercase English letters. In one move he can swap two adjacent letters of the string. For example, he can transform a string "ABBC" into "BABC" or "ABCB" in one move.
Limak wants to obtain a string without a substring "VK" (i.e. there should be no letter 'V' immediately followed by letter 'K'). It can be easily proved that it's possible for any initial string $s$ .
What is the minimum possible number of moves Limak can do?
输入格式
The first line of the input contains an integer $n$ ( $1<=n<=75$ ) — the length of the string.
The second line contains a string $s$ , consisting of uppercase English letters. The length of the string is equal to $n$ .
The second line contains a string $s$ , consisting of uppercase English letters. The length of the string is equal to $n$ .
输出格式
Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK".
输入输出样例
输入 #1
4 VKVK
输出 #1
3
输入 #2
5 BVVKV
输出 #2
2
输入 #3
7 VVKEVKK
输出 #3
3
输入 #4
20 VKVKVVVKVOVKVQKKKVVK
输出 #4
8
输入 #5
5 LIMAK
输出 #5
0
In the first sample, the initial string is "VKVK". The minimum possible number of moves is $3$ . One optimal sequence of moves is:
1. Swap two last letters. The string becomes "VKKV".
2. Swap first two letters. The string becomes "KVKV".
3. Swap the second and the third letter. The string becomes "KKVV". Indeed, this string doesn't have a substring "VK".
In the second sample, there are two optimal sequences of moves. One is "BVVKV" $→$ "VBVKV" $→$ "VVBKV". The other is "BVVKV" $→$ "BVKVV" $→$ "BKVVV".
In the fifth sample, no swaps are necessary.
1. Swap two last letters. The string becomes "VKKV".
2. Swap first two letters. The string becomes "KVKV".
3. Swap the second and the third letter. The string becomes "KKVV". Indeed, this string doesn't have a substring "VK".
In the second sample, there are two optimal sequences of moves. One is "BVVKV" $→$ "VBVKV" $→$ "VVBKV". The other is "BVVKV" $→$ "BVKVV" $→$ "BKVVV".
In the fifth sample, no swaps are necessary.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted