当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3913:SUFFIX

题目描述
A string is a list of characters containing only letter ‘a’ to ‘z’. For example: “abcdefg”, “isun” are valid strings. “rocket323” is not a valid string.

A suffix of a string suf[i] is the list of characters at positions from i to n-1 (positions are labeled from 0 to n – 1, n is length of the string). For the string “hustacm”, suf[0] = “hustacm”, suf[1] = “ustacm”, suf[3] = “tacm”, suf[6] = “m”.

The suffix list L of a string is a permutation of numbers from 0 to n-1(n is length of the string), which satisfy the following condition:
suf[L[0]] < suf[L[1]] < suf[L[2]] < … < suf[L[n-1]].

For the string “aabac”, its suffix list is [0, 1, 3, 2, 4].
Here comes the question: Given a string S and a suffix list L, you are to change minimum number of characters of S so that the suffix list of the new string is equal to L.
输入解释
There are multiple cases, for each case:
  The first line is integer n representing the length of the string. (1 <= n <= 500)
  The second line is the string.
  The third line is a permutation of numbers from 0 to n-1.
输出解释
For each case, output the minimum number of characters to change in order to satisfy the condition above, if there is no solution, just output -1.
输入样例
3
abc
0 1 2
3
aab
2 0 1
输出样例
0
2
来自杭电HDUOJ的附加信息
Recommend lcy

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3913

最后修改于 2020-10-25T23:08:13+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)