CF B. Kolya and Tandem Repeat
来源:互联网 发布:淘宝客服模块代码 编辑:程序博客网 时间:2024/06/05 14:56
Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
Input
The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.
Output
Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.
Sample test(s)
Input
aaba
2
Output
6
Input
aaabbbb
2
Output
6
Input
abracadabra
10
Output
20
A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: si = si + n.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
Input
The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.
Output
Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.
Sample test(s)
Input
aaba
2
Output
6
Input
aaabbbb
2
Output
6
Input
abracadabra
10
Output
20
Note
A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: si = si + n.
In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.
暴力枚举所有情况
#include <cstdio>#include <iostream>#include <cstring>using namespace std;char str[205];int main(){ int n; while(cin>>str>>n){ int len = strlen(str); int L = len+n-(len+n)%2; //保证长度为偶数 if(len <= n){ cout<<L<<endl; continue; } int maxlen = 0; for(int i=0; i<len; i++){ //枚举起始位置 for(int j=1; i+j-1<=len-1; j++){ //枚举一半的长度 int cnt = 0; for(int k=i; k<=i+j-1; k++){ //判断 if(len <= k+j && k+j < len+n) cnt++; //下标 else if(str[k] == str[k+j]) cnt++; } if(cnt == j && 2*cnt > maxlen) maxlen = 2*cnt; } } cout<<maxlen<<endl; } return 0;}
0 0
- CF B. Kolya and Tandem Repeat
- CF 253B. Kolya and Tandem Repeat
- CF 443B(253B)Kolya and Tandem Repeat
- Codeforces 443 B. Kolya and Tandem Repeat
- CodeForces-443B Kolya and Tandem Repeat
- CodeForces 443B Kolya and Tandem Repeat
- Kolya and Tandem Repeat
- Kolya and Tandem Repeat
- Kolya and Tandem Repeat - CF#253 (Div. 2)B (443B) 哈希或水题
- cf443B Kolya and Tandem Repeat
- Codeforces 442B Kolya and Tandem Repeat(暴力)
- CF 584B Kolya and Tanya
- CF#324-B. Kolya and Tanya-组合数学题
- cf#324 Div.2 Problem B Kolya and Tanya
- B. Kolya and Tanya
- cf B. Kolya and Tanya (快速幂_注意取模)
- Codeforces Round #324 B Kolya and Tanya
- codeforces 584B Kolya and Tanya
- Linux启动过程
- 加班防猝死的十个小建议
- sql学习笔记(一)
- Boost Replaceable by C++11 language features or libraries
- cubieboard python gpio
- CF B. Kolya and Tandem Repeat
- Iphone开发常识
- 各种正则表达式转载
- 机房收费系统数据库设计
- 奇数位于偶数的前面在一个数组中
- VC创建不规则窗口
- myeclipse 红色叹号的原因
- apache虚拟主机配置
- Regular Expression基础解析正则表达式