CF1183E.Subsequences (easy version)

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The only difference between the easy and the hard versions is constraints.

A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string "abaca" the following strings are subsequences: "abaca", "aba", "aaa", "a" and "" (empty string). But the following strings are not subsequences: "aabaca", "cb" and "bcaa".

You are given a string ss consisting of nn lowercase Latin letters.

In one move you can take any subsequence tt of the given string and add it to the set SS. The set SS can't contain duplicates. This move costs n−∣t∣n - |t|, where ∣t∣|t| is the length of the added subsequence (i.e. the price equals to the number of the deleted characters).

Your task is to find out the minimum possible total cost to obtain a set SS of size kk or report that it is impossible to do so.

简单版本与困难版本的唯一区别在于约束条件。

子序列是指通过删除原字符串中的一些字符(也可以不删)而得到的字符串,且剩余字符的相对顺序保持不变。被删除的字符不必连续,它们之间可以存在任意间隔。例如,对于字符串 "abaca",以下字符串均为其子序列:"abaca"、"aba"、"aaa"、"a" 和 ""(空字符串);但以下字符串不是其子序列:"aabaca"、"cb" 和 "bcaa"。

给定一个由 nn 个小写拉丁字母组成的字符串 ss。

在一次操作中,你可以选取 ss 的任意一个子序列 tt,并将其加入集合 SS 中。集合 SS 中不能包含重复元素。该操作的代价为 n−∣t∣n - |t|,其中 ∣t∣|t| 表示所添加子序列的长度(即代价等于被删除的字符个数)。

你的任务是求出获得大小为 kk 的集合 SS 所需的最小总代价;若无法实现,则报告这是不可能的。

输入格式

The first line of the input contains two integers nn and kk (1≤n,k≤1001 \le n, k \le 100) — the length of the string and the size of the set, correspondingly.

The second line of the input contains a string ss consisting of nn lowercase Latin letters.

输入的第一行包含两个整数 nn 和 kk(1≤n,k≤1001 \le n, k \le 100),分别表示字符串的长度和集合的大小。

输入的第二行包含一个由 nn 个小写拉丁字母组成的字符串 ss。

输出格式

Print one integer — if it is impossible to obtain the set SS of size kk, print -1. Otherwise, print the minimum possible total cost to do it.

输出一个整数——如果无法得到大小为 kk 的集合 SS,则输出 −1-1;否则,输出实现该目标的最小总代价。

输入输出样例

  • 输入#1

    4 5
    asdf

    输出#1

    4
  • 输入#2

    5 6
    aaaaa

    输出#2

    15
  • 输入#3

    5 7
    aaaaa

    输出#3

    -1
  • 输入#4

    10 100
    ajihiushda

    输出#4

    233

说明/提示

In the first example we can generate SS = { "asdf", "asd", "adf", "asf", "sdf" }. The cost of the first element in SS is 00 and the cost of the others is 11. So the total cost of SS is 44.

在第一个例子中,我们可以生成集合 SS = { "asdf", "asd", "adf", "asf", "sdf" }。SS 中第一个元素的成本为 00,其余元素的成本均为 11。因此,SS 的总成本为 44。

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

首页