#452
Unrated
Moortal Cowmbat
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie has been playing the popular fighting game Moortal Cowmbat for a long time now. However, the game developers have recently rolled out an update that is forcing Bessie to change her play style.

The game uses MM buttons labeled by the first MM lowercase letters (1M261 \leq M \leq 26). Bessie's favorite combo of moves in the game is a length-NN string SS of button presses (1N1051 \leq N \leq 10^5). However, due to the most recent update, every combo must now be made from a series of "streaks", where a streak is defined as a series of the same button pressed at least KK times in a row (1KN1 \leq K \leq N). Bessie wants to modify her favorite combo to produce a new combo of the same length NN, but made from streaks of button presses to satisfy the change in rules.

It takes aija_{ij} days for Bessie to train herself to press button jj instead of button ii at any specific location in her combo (i.e. it costs aija_{ij} to change a single specific letter in SS from ii to jj). Note that it might take less time to switch from using button ii to an intermediate button kk and then from button kk to button jj rather than from ii to jj directly (or more generally, there may be a path of changes starting with ii and ending with jj that gives the best overall cost for switching from button ii ultimately to button jj).

Help Bessie determine the smallest possible number of days she needs to create a combo that supports the new requirements.

SCORING:

Test cases 2-4 satisfy N1000,K50.N\le 1000, K\le 50.Test cases 5-8 satisfy N30,000,K50.N\le 30,000, K\le 50.

입력

The first line of input contains NN, MM, and KK. The second line contains SS, and the final MM lines contain an M×MM\times M matrix of values aija_{ij}, where aija_{ij} is an integer in the range 010000 \ldots 1000 and aii=0a_{ii} = 0 for all ii.

출력

Output a single number, representing the minimum number of days Bessie needs to change her combo into one that satisfies the new requirements.

예제 입력 1

5 5 2
abcde
0 1 4 4 4
2 0 4 4 4
6 5 0 3 2
5 5 5 0 4
3 7 0 5 0

예제 출력 1

5
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.