2 条题解
-
0
def count_vk_occurrences(s): count = 0 for i in range(len(s) - 1): if s[i:i+2] == "VK": count += 1 return count def maximize_vk_occurrences(n, s): max_count = count_vk_occurrences(s) for i in range(n): original_char = s[i] # 尝试将当前字符替换为'V' if original_char != 'V': s_replaced_with_v = s[:i] + 'V' + s[i+1:] max_count = max(max_count, count_vk_occurrences(s_replaced_with_v)) # 尝试将当前字符替换为'K' if original_char != 'K': s_replaced_with_k = s[:i] + 'K' + s[i+1:] max_count = max(max_count, count_vk_occurrences(s_replaced_with_k)) # 恢复原始字符,以便进行下一次替换尝试 s = s[:i] + original_char + s[i+1:] return max_count # 读取输入 n = int(input()) s = input() # 输出结果 print(maximize_vk_occurrences(n, s))不喜欢写注释
- 1
信息
- ID
- 703
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 13
- 已通过
- 5
- 上传者