CF1132F.Clear the String

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a string ss of length nn 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 ss .

输入格式

The first line contains one integer nn ( 1n5001 \le n \le 500 ) — the length of string ss .

The second line contains the string ss ( s=n|s| = n ) consisting of lowercase Latin letters.

输出格式

Output a single integer — the minimal number of operation to delete string ss .

输入输出样例

  • 输入#1

    5
    abaca
    

    输出#1

    3
    
  • 输入#2

    8
    abcddcba
    

    输出#2

    4
    
首页