Covers
시간 제한1초메모리 제한2048 MB
빈 문자열에서 시작해 패턴 P를 붙이는 연산은 무료, 문자 하나 추가와 끝 문자 삭제는 비용이 들 때 T를 만드는 최소 비용을 구한다.
문제
You are given two strings and . Your aim is to create with . You first begin with an empty string. Then you can do one of three operations shown below.
- Put at the end of the current string. This operation costs .
- Put a character at the end of the current string. This operation costs .
- Delete characters at the end of the current string and put . This operation costs the number of characters you deleted.
For example, assume that aabaabaa and aaba. There are two ways to create with as follows, where ε denotes an empty string.
ε→aaba→aabaa→aabaab→aabaaba→aabaabaa, orε→aaba→aab→aabaaba→aabaabaa.
The former costs four as it first puts (cost ) and four characters (a, b, a, and a, cost ). The latter costs two as it first puts (cost ), then deletes one character (a, cost ) and puts (cost ), and finally puts a character (a, cost ). We choose the latter and we can see that it has the minimum cost.
Given and , write a program which computes the minimum cost to create with .
입력
Your program is to read from standard input. The input starts with a line containing two integers, and (, ), where is the length of and is that of . The second line contains and the third line contains . Both and are in English lower-case letters.
출력
Your program is to write to standard output. Print exactly one line. The line should contain the minimum cost to create with .