#P1279. 字串距离
字串距离
Description
Given a string , we call any new string formed by inserting any number of spaces at the beginning, end, or between characters of an extended string of . For example, if is , then , , and are all extended strings of , where denotes the space character.
If is an extended string of , is an extended string of , and and have the same length, then we define the distance between and as the sum of the distances at corresponding positions. The distance between two non-space characters is defined as the absolute difference of their ASCII codes. The distance between a space character and any other character is a given constant , and the distance between a space and a space is . Among all extended strings of and , there must exist two extended strings and of equal length such that the distance between and is minimized. We define this minimal value as the distance between strings and .
Please write a program to compute the distance between strings and .
Input Format
The first line contains string , and the second line contains string . Both and consist of lowercase letters, and each has length at most . The third line contains an integer , which is the distance between a space and any other character.
Output Format
Output a single line containing an integer, which is the distance between and .
cmc
snmn
2
10
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号