http://codeforces.com/contest/1029/problem/A

You are given a string tt consisting of nn lowercase Latin letters and an integer number kk.

Let's define a substring of some string ss with indices from ll to rr as s[l…r]s[l…r].

Your task is to construct such string ss of minimum possible length that there are exactly kk positions ii such that s[i…i+n−1]=ts[i…i+n−1]=t. In other words, your task is to construct such string ss of minimum possible length that there are exactly kk substrings of ss equal to tt.

It is guaranteed that the answer is always unique.

Input

The first line of the input contains two integers nn and kk (1≤n,k≤501≤n,k≤50) — the length of the string tt and the number of substrings.

The second line of the input contains the string tt consisting of exactly nn lowercase Latin letters.

Output

Print such string ss of minimum possible length that there are exactly kk substrings of ss equal to tt.

It is guaranteed that the answer is always unique.

Examples
input

Copy
3 4
aba
output

Copy
ababababa
input

Copy
3 2
cat
output

Copy
catcat

代码:

#include <bits/stdc++.h>
using namespace std; int N, M;
string s; int main() {
scanf("%d%d", &N, &M);
cin >> s;
int temp;
for(int i = 0; i < N; i ++) {
if(s.substr(0, i) == s.substr(N - i, i))
temp = i;
}
for(int i = 1; i < M; i ++)
cout << s.substr(0, N - temp);
cout << s <<endl;
return 0;
}

  

CodeForces A. Many Equal Substrings的更多相关文章

  1. Many Equal Substrings CodeForces - 1029A (kmp next数组应用)

    题目大意 题目看样例也能猜到就是输出最短的循环串. 吐槽 明明是div3第一题为啥子还会用到kmp的知识? 解法 这个题仔细看发现是求最长可去除的后缀,也就是说去除跟下一个相同的字符串还能连接起来.这 ...

  2. Codeforces gym101612 E.Equal Numbers(贪心)

    传送:http://codeforces.com/gym/101612 题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的 ...

  3. codeforces D. Count Good Substrings

    http://codeforces.com/contest/451/problem/D 题意:给你一个字符串,然后找出奇数和偶数长度的子串的个数,这些字串符合,通过一些连续相同的字符合并后是回文串. ...

  4. 【CodeForces】914 F. Substrings in a String bitset

    [题目]F. Substrings in a String [题意]给定小写字母字符串s,支持两种操作:1.修改某个位置的字符,2.给定字符串y,查询区间[l,r]内出现y多少次.|s|,Σ|y|&l ...

  5. Codeforces 622C Not Equal on a Segment 【线段树 Or DP】

    题目链接: http://codeforces.com/problemset/problem/622/C 题意: 给定序列,若干查询,每个查询给定区间和t,输出区间内任意一个不等于t的元素的位置. 分 ...

  6. 【leetcode】1208. Get Equal Substrings Within Budget

    题目如下: You are given two strings s and t of the same length. You want to change s to t. Changing the  ...

  7. Codeforces 1188D Make Equal DP

    题意:给你个序列,你可以给某个数加上2的幂次,问最少多少次可以让所有的数相等. 思路(官方题解):我们先给序列排序,假设bit(c)为c的二进制数中1的个数,假设所有的数最后都成为了x, 显然x &g ...

  8. Codeforces C. Almost Equal (数学规律)

    题目链接:http://codeforces.com/contest/1206/problem/C 题解 : 观察可以发现当n为偶数时,1 - 2n是不满足题意的,可以举例n = 2,n = 4试一试 ...

  9. Codeforces 1188D - Make Equal(dp)

    Codeforces 题目传送门 & 洛谷题目传送门 首先我们考虑枚举最后这 \(n\) 个数变成的值 \(v\),那么需要的操作次数即为 \(\sum\limits_{i=1}^n\text ...

随机推荐

  1. Windows核心编程-作业

    原文链接:http://zhujiangtao.com/?p=983 作业 作业 一个简单例程 CreateJobObject 创建作业 作业限制和 SetInformationJobObject A ...

  2. Bootstarp学习教程(7) 表单

    基本案例:“form-control”修饰的<input>.<textarea>和<select>元素都将被默认设置为width: 100%;表单控件包裹在&quo ...

  3. ios xmppFramework框架的导入步骤和介绍

    一个将要开发xmpp的项目,建议在项目刚创建就导入框架,这样可以避免一些自己操作失误造成不必要的损失. xmpp中最常用的框架就是 xmppFrameWork 第一种方法直接拖 1> 拖入文件夹 ...

  4. C#+Winform开发窗体程序

    学习笔记 第一章:winform基础 一.概述 1.Windows Form(简称WinForm) 是微软.NET平台下用于开发"图形界面"应用程序的组件. 2.C/S架构 客户机 ...

  5. springMVC-数据绑定

    定义: 将http请求中参数绑定到Handler业务方法 常用数据绑定类型 1.  基本数据类型 不能为其它类型和null值 2.  包装类 可以为其它对象,全部转成null值 3.  数组 多个对象 ...

  6. Maven - 配置镜像仓库

    默认仓库的配置(全球中央仓库): 可以打开maven的安装目录/conf/settings.xml文件,配置镜像,找到如下一段配置,这里默认没有配置任何镜像,但是有一个被注释的配置范例: id: 镜像 ...

  7. springMVC入门二

    一.准备工作 参考springMVC入门一,搭建maven项目如下: 前台结构如下: 项目介绍:使用springMVC实现前后台数据交互,例如controller返回json,页面传入pojo 二.具 ...

  8. PHP ping

    <?php /// start ping.inc.php /// $g_icmp_error = "No Error"; // timeout in ms function ...

  9. PAT (Basic Level) Practice 1023 组个最小数

    个人练习 给定数字 0-9 各若干个.你可以以任意顺序排列这些数字,但必须全部使用.目标是使得最后得到的数尽可能小(注意 0 不能做首位).例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的 ...

  10. ln -s 软链接产生Too many levels of symbolic links错误

    不能使用相对路径, ln -s ./cmake /usr/bin/ 而是要 ln -s /usr/local/bin/cmake /usr/bin/