CF1120C.Compress String

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Suppose you are given a string ss of length nn consisting of lowercase English letters. You need to compress it using the smallest possible number of coins.

To compress the string, you have to represent ss as a concatenation of several non-empty strings: s=t1t2…tks = t_{1} t_{2} \ldots t_{k}. The ii-th of these strings should be encoded with one of the two ways:

  • if ∣ti∣=1|t_{i}| = 1, meaning that the current string consists of a single character, you can encode it paying aa coins;
  • if tit_{i} is a substring of t1t2…ti−1t_{1} t_{2} \ldots t_{i - 1}, then you can encode it paying bb coins.

A string xx is a substring of a string yy if xx can be obtained from yy by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

So your task is to calculate the minimum possible number of coins you need to spend in order to compress the given string ss.

假设你得到一个长度为 nn 的字符串 ss,它仅由小写英文字母组成。你需要用尽可能少的硬币对该字符串进行压缩。

为了压缩该字符串,你必须将 ss 表示为若干个非空字符串的拼接:s=t1t2…tks = t_{1} t_{2} \ldots t_{k}。其中第 ii 个字符串 tit_i 必须采用以下两种方式之一进行编码:

  • 若 ∣ti∣=1|t_{i}| = 1(即当前字符串仅含一个字符),则可花费 aa 枚硬币对其进行编码;
  • 若 tit_{i} 是 t1t2…ti−1t_{1} t_{2} \ldots t_{i - 1} 的一个子串,则可花费 bb 枚硬币对其进行编码。

字符串 xx 是字符串 yy 的子串,当且仅当 xx 可通过从 yy 的开头删除若干(可能为零或全部)字符、并从 yy 的末尾删除若干(可能为零或全部)字符而得到。

因此,你的任务是计算为压缩给定字符串 ss 所需花费的最少硬币数。

输入格式

The first line contains three positive integers, separated by spaces: nn, aa and bb (1≤n,a,b≤50001 \leq n, a, b \leq 5000) — the length of the string, the cost to compress a one-character string and the cost to compress a string that appeared before.

The second line contains a single string ss, consisting of nn lowercase English letters.

第一行包含三个正整数,以空格分隔:nn、aa 和 bb(1≤n,a,b≤50001 \leq n, a, b \leq 5000)——分别表示字符串的长度、压缩单字符字符串的代价,以及压缩此前已出现过的字符串的代价。

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

输出格式

Output a single integer — the smallest possible number of coins you need to spend to compress ss.

输出一个整数——压缩字符串 ss 所需的最少硬币数量。

输入输出样例

  • 输入#1

    3 3 1
    aba

    输出#1

    7
  • 输入#2

    4 1 1
    abcd

    输出#2

    4
  • 输入#3

    4 10 1
    aaaa

    输出#3

    12

说明/提示

In the first sample case, you can set t1=t_{1} = 'a', t2=t_{2} = 'b', t3=t_{3} = 'a' and pay 3+3+1=73 + 3 + 1 = 7 coins, since t3t_{3} is a substring of t1t2t_{1}t_{2}.

In the second sample, you just need to compress every character by itself.

In the third sample, you set t1=t2=t_{1} = t_{2} = 'a', t3=t_{3} = 'aa' and pay 10+1+1=1210 + 1 + 1 = 12 coins, since t2t_{2} is a substring of t1t_{1} and t3t_{3} is a substring of t1t2t_{1} t_{2}.

在第一个样例中,你可以设置 t1=t_{1} = 'a'、t2=t_{2} = 'b'、t3=t_{3} = 'a',并支付 3+3+1=73 + 3 + 1 = 7 枚硬币,因为 t3t_{3} 是 t1t2t_{1}t_{2} 的子串。

在第二个样例中,你只需将每个字符单独压缩即可。

在第三个样例中,你设置 t1=t2=t_{1} = t_{2} = 'a'、t3=t_{3} = 'aa',并支付 10+1+1=1210 + 1 + 1 = 12 枚硬币,因为 t2t_{2} 是 t1t_{1} 的子串,且 t3t_{3} 是 t1t2t_{1} t_{2} 的子串。

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

首页