CF1634A.Reverse and Concatenate

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Real stupidity beats artificial intelligence every time.

— Terry Pratchett, Hogfather, Discworld

You are given a string ss of length nn and a number kk. Let's denote by rev(s)rev(s) the reversed string ss (i.e. rev(s)=snsn−1...s1rev(s) = s_n s_{n-1} ... s_1). You can apply one of the two kinds of operations to the string:

  • replace the string ss with s+rev(s)s + rev(s)
  • replace the string ss with rev(s)+srev(s) + s

How many different strings can you get as a result of performing exactly kk operations (possibly of different kinds) on the original string ss?

In this statement we denoted the concatenation of strings ss and tt as s+ts + t. In other words, s+t=s1s2...snt1t2...tms + t = s_1 s_2 ... s_n t_1 t_2 ... t_m, where nn and mm are the lengths of strings ss and tt respectively.

真正的愚蠢永远胜过人工智能。

——特里·普拉切特,《 Hogfather 》,《碟形世界》

给定一个长度为 nn 的字符串 ss 和一个整数 kk。记 rev(s)rev(s) 为字符串 ss 的反转(即 rev(s)=snsn−1…s1rev(s) = s_n s_{n-1} \dots s_1)。你可以对字符串执行以下两种操作之一:

  • 将字符串 ss 替换为 s+rev(s)s + rev(s);
  • 将字符串 ss 替换为 rev(s)+srev(s) + s。

对原始字符串 ss 恰好执行 kk 次操作(每次操作可以是上述两种类型之一),最多能得到多少个不同的字符串?

在本题中,我们用 s+ts + t 表示字符串 ss 与 tt 的拼接。换言之,若 ss 和 tt 的长度分别为 nn 和 mm,则 s+t=s1s2…snt1t2…tms + t = s_1 s_2 \dots s_n t_1 t_2 \dots t_m。

输入格式

The first line contains one integer tt (1≤t≤1001 \le t \le 100) — number of test cases. Next 2⋅t2 \cdot t lines contain tt test cases:

The first line of a test case contains two integers nn and kk (1≤n≤1001 \le n \le 100, 0≤k≤10000 \le k \le 1000) — the length of the string and the number of operations respectively.

The second string of a test case contains one string ss of length nn consisting of lowercase Latin letters.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。接下来的 2⋅t2 \cdot t 行包含 tt 个测试用例:

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤1001 \le n \le 100,0≤k≤10000 \le k \le 1000),分别表示字符串的长度和操作次数。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss,由小写拉丁字母组成。

输出格式

For each test case, print the answer (that is, the number of different strings that you can get after exactly kk operations) on a separate line.

It can be shown that the answer does not exceed 10910^9 under the given constraints.

对于每个测试用例,在单独一行中输出答案(即:恰好执行 kk 次操作后所能得到的不同字符串的个数)。

在给定约束条件下,可以证明该答案不超过 10910^9。

输入输出样例

  • 输入#1

    4
    3 2
    aab
    3 3
    aab
    7 1
    abacaba
    2 0
    ab

    输出#1

    2
    2
    1
    1

说明/提示

In the first test case of the example:

After the first operation the string ss can become either aabbaa or baaaab. After the second operation there are 2 possibilities for ss: aabbaaaabbaa and baaaabbaaaab.

在示例的第一个测试用例中:

第一次操作后,字符串 ss 可能变为 aabbaa 或 baaaab。第二次操作后,ss 有 2 种可能:aabbaaaabbaa 和 baaaabbaaaab。

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

首页