305437: CF1031D. Minimum path
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Minimum path
题意翻译
## 题目描述 给你一个n×n的全是小写字母的矩阵,你能改变k个字母 你要从左上角走到右下角,且每步只能移动到右边或下边的字母上。 对于每一条路径都会得到一个由你经过的所有字母组成的字符串。当然,他的长度是2×n-1. 在你最多改动k个字母的情况下,找到一个得到字符串字典序最小的路径. 一个字符串a如果字典序比字符串b小,那他们第一个不同的字符在a中小于b. ## 输入输出格式 #### 输入格式: 第一行包括两个整数n和k(1≤n≤2000,0≤k≤n2),矩阵的大小和你最多能改变的字母数. 下面n行,每行n个小写字母. #### 输出格式: 在你最多改动k个字母的情况下,得到的一个字符串字典序最小的路径.题目描述
You are given a matrix of size $ n \times n $ filled with lowercase English letters. You can change no more than $ k $ letters in this matrix. Consider all paths from the upper left corner to the lower right corner that move from a cell to its neighboring cell to the right or down. Each path is associated with the string that is formed by all the letters in the cells the path visits. Thus, the length of each string is $ 2n - 1 $ . Find the lexicographically smallest string that can be associated with a path after changing letters in at most $ k $ cells of the matrix. A string $ a $ is lexicographically smaller than a string $ b $ , if the first different letter in $ a $ and $ b $ is smaller in $ a $ .输入输出格式
输入格式
The first line contains two integers $ n $ and $ k $ ( $ 1 \le n \le 2000 $ , $ 0 \le k \le n^2 $ ) — the size of the matrix and the number of letters you can change. Each of the next $ n $ lines contains a string of $ n $ lowercase English letters denoting one row of the matrix.
输出格式
Output the lexicographically smallest string that can be associated with some valid path after changing no more than $ k $ letters in the matrix.
输入输出样例
输入样例 #1
4 2
abcd
bcde
bcad
bcde
输出样例 #1
aaabcde
输入样例 #2
5 3
bwwwz
hrhdh
sepsp
sqfaf
ajbvw
输出样例 #2
aaaepfafw
输入样例 #3
7 6
ypnxnnp
pnxonpm
nxanpou
xnnpmud
nhtdudu
npmuduh
pmutsnz
输出样例 #3
aaaaaaadudsnz