CF771D.Bear and Company

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 正在为一场编程竞赛准备题目。当然,在题目描述中提及赞助商名称是不专业的。Limak 对此非常重视,因此他打算修改某些单词。为了确保修改后的题目仍可读,他将尽量使每个单词的改动最小。

Limak 有一个由大写英文字母组成的字符串 ss。在一次操作中,他可以交换字符串中两个相邻的字母。例如,他可以在一次操作中将字符串 "ABBC" 变为 "BABC" 或 "ABCB"。

Limak 希望得到一个不包含子串 "VK" 的字符串(即不能出现字母 'V' 后紧跟字母 'K' 的情况)。可以很容易地证明:对于任意初始字符串 ss,这样的目标字符串总能达成。

Limak 所需的最少操作次数是多少?

输入格式

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.

输入的第一行包含一个整数 nn(1≤n≤751 \leq n \leq 75)—— 字符串的长度。

第二行包含一个字符串 ss,由大写英文字母组成,其长度为 nn。

输出格式

Print one integer, denoting the minimum possible number of moves Limak can do, in order to obtain a string without a substring "VK".

输出一个整数,表示 Limak 为得到不含子串 "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.

在第一个样例中,初始字符串为 "VKVK"。最少可能的操作次数为 3。其中一种最优操作序列如下:

  1. 交换最后两个字母,字符串变为 "VKKV"。
  2. 交换前两个字母,字符串变为 "KVKV"。
  3. 交换第二个与第三个字母,字符串变为 "KKVV"。确实,该字符串不包含子串 "VK"。

在第二个样例中,存在两种最优操作序列。其一为 "BVVKV" → "VBVKV" → "VVBKV";其二为 "BVVKV" → "BVKVV" → "BKVVV"。

在第五个样例中,无需进行任何交换操作。

输入解题思路,AI测评打分。不知道怎么写?

首页