A14778 | Reverse and Concatenate
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Real stupidity beats artificial intelligence every time.
— Terry Pratchett, Hogfather, Discworld
You are given a string $s$ of length $n$ and a number $k$ . Let's denote by $rev(s)$ the reversed string $s$ (i.e. $rev(s) = s_n s_{n-1} ... s_1$ ). You can apply one of the two kinds of operations to the string:
- replace the string $s$ with $s + rev(s)$
- replace the string $s$ with $rev(s) + s$
How many different strings can you get as a result of performing exactly $k$ operations (possibly of different kinds) on the original string $s$ ?
In this statement we denoted the concatenation of strings $s$ and $t$ as $s + t$ . In other words, $s + t = s_1 s_2 ... s_n t_1 t_2 ... t_m$ , where $n$ and $m$ are the lengths of strings $s$ and $t$ respectively.
— Terry Pratchett, Hogfather, Discworld
You are given a string $s$ of length $n$ and a number $k$ . Let's denote by $rev(s)$ the reversed string $s$ (i.e. $rev(s) = s_n s_{n-1} ... s_1$ ). You can apply one of the two kinds of operations to the string:
- replace the string $s$ with $s + rev(s)$
- replace the string $s$ with $rev(s) + s$
How many different strings can you get as a result of performing exactly $k$ operations (possibly of different kinds) on the original string $s$ ?
In this statement we denoted the concatenation of strings $s$ and $t$ as $s + t$ . In other words, $s + t = s_1 s_2 ... s_n t_1 t_2 ... t_m$ , where $n$ and $m$ are the lengths of strings $s$ and $t$ respectively.
输入格式
The first line contains one integer $t$ ( $1 \le t \le 100$ ) — number of test cases. Next $2 \cdot t$ lines contain $t$ test cases:
The first line of a test case contains two integers $n$ and $k$ ( $1 \le n \le 100$ , $0 \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 $s$ of length $n$ consisting of lowercase Latin letters.
The first line of a test case contains two integers $n$ and $k$ ( $1 \le n \le 100$ , $0 \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 $s$ of length $n$ consisting of lowercase Latin letters.
输出格式
For each test case, print the answer (that is, the number of different strings that you can get after exactly $k$ operations) on a separate line.
It can be shown that the answer does not exceed $10^9$ under the given constraints.
It can be shown that the answer does not exceed $10^9$ under the given constraints.
输入输出样例
输入 #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 $s$ can become either aabbaa or baaaab. After the second operation there are 2 possibilities for $s$ : aabbaaaabbaa and baaaabbaaaab.
After the first operation the string $s$ can become either aabbaa or baaaab. After the second operation there are 2 possibilities for $s$ : aabbaaaabbaa and baaaabbaaaab.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted