CF1132F.Clear the String
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s of length n consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if all letters in the substring you delete are equal. For example, after deleting substring bbbb from string abbbbaccdd we get the string aaccdd.
Calculate the minimum number of operations to delete the whole string s.
给你一个长度为 n 的字符串 s,其中仅包含小写拉丁字母。你可以对这个字符串执行若干操作:每次操作中,你可以删除该字符串的一个连续子串,但要求所删除的子串中所有字符都相同。例如,从字符串 abbbbaccdd 中删除子串 bbbb 后,得到字符串 aaccdd。
请计算将整个字符串 s 完全删除所需的最少操作次数。
输入格式
The first line contains one integer n (1≤n≤500) — the length of string s.
The second line contains the string s (∣s∣=n) consisting of lowercase Latin letters.
第一行包含一个整数 n(1≤n≤500)—— 字符串 s 的长度。
第二行包含字符串 s(∣s∣=n),由小写拉丁字母组成。
输出格式
Output a single integer — the minimal number of operation to delete string s.
输出一个整数——删除字符串 s 所需的最少操作次数。
输入输出样例
输入#1
5 abaca
输出#1
3
输入#2
8 abcddcba
输出#2
4
输入解题思路,AI测评打分。不知道怎么写?