# CF1496A Split it!（数学分析）

Kawashiro Nitori is a girl who loves competitive programming.

One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.

Given a string ss and a parameter kk , you need to check if there exist k+1k+1 non-empty strings a_1,a_2...,a_{k+1}a1,a2...,ak+1 , such that s=a_1+a_2+\ldots +a_k+a_{k+1}+R(a_k)+R(a_{k-1})+\ldots+R(a_{1}).s=a1+a2+…+ak+ak+1+R(ak)+R(ak−1)+…+R(a1). Here ++ represents concatenation. We define R(x)R(x) as a reversed string xx . For example R(abcd) = dcbaR(abcd)=dcba . Note that in the formula above the part R(a\_{k+1})R(a_k+1) is intentionally skipped.

## 输入格式

The input consists of multiple test cases. The first line contains a single integer tt ( 1\le t\le 1001≤t≤100 ) — the number of test cases. The description of the test cases follows.

The first line of each test case description contains two integers nn , kk ( 1\le n\le 1001≤n≤100 , 0\le k\le \lfloor \frac{n}{2} \rfloor0≤k≤⌊2n⌋ ) — the length of the string ss and the parameter kk .

The second line of each test case description contains a single string ss of length nn , consisting of lowercase English letters.

## 输出格式

For each test case, print "YES" (without quotes), if it is possible to find a_1,a_2,\ldots,a_{k+1}a1,a2,…,ak+1 , and "NO" (without quotes) otherwise.

You can print letters in any case (upper or lower).

# 题意翻译

## 题目描述

s=a1+a2+...+ak+ak+1+R(ak)+...+R(a2)+R(a1)

## 数据范围

1≤n≤100,0≤k≤⌊ n/2⌋

## 输入输出样例

7
5 1
qwqwq
2 1
ab
3 1
ioi
4 2
icpc
22 0
dokidokiliteratureclub
19 8
imteamshanghaialice
6 3
aaaaaa

YES
NO
YES
NO
YES
NO
NO

#include <bits/stdc++.h>
using namespace std;
int t, n, k;
char s[105];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d%s", &n, &k, s);
int cnt = 0;
for (int i = 0, j = n - 1; i < j - 1; ++i, --j) {//结束条件是刚刚好i=j
if (s[i] != s[j]) {
break;
}
++cnt;//想不通就想qweaq为什么是YES;这就是数学规律
}
puts(cnt >= k ? "YES" : "NO");
}
}

|
4月前
|

BBC Brown Boveri 216AB61 HESG324013R100 / HESG216881 216DB61模块
BBC Brown Boveri 216AB61 HESG324013R100 / HESG216881 216DB61模块
33 0
|
4月前
|
Java C++ Python

29 0
|
12月前
CF1342B Binary Period（数学分析)
CF1342B Binary Period（数学分析)
20 0
|
2月前
|

CF 1561 D. Up the Strip(数学+思维)
【7月更文挑战第5天】
43 10
|
3月前
CF 1538 G. Gift Set (贪心+思维)
【6月更文挑战第14天】
26 0
|
12月前
CF219A k-String（数学分析）
CF219A k-String（数学分析）
59 0
|
12月前
|

CF1547B Alphabetical Strings（了解字符串的的一些规律）
CF1547B Alphabetical Strings（了解字符串的的一些规律）
67 0
|
12月前
|

CF1550A Find The Array（贪心算法）
CF1550A Find The Array（贪心算法）
30 0
|
12月前
|

CF1029A Many Equal Substrings（kmp！！！！最通俗易懂的文章模板）
CF1029A Many Equal Substrings（kmp！！！！最通俗易懂的文章模板）
43 0
cf 1042B（状压dp）
cf 1042B（状压dp）
60 0