PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000005. Bức tường chữ số (Wall)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bức tường chữ số (Wall)
Wall
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
A wall has digits from to or empty cells indicated by . Changing to costs and transformations may be chained. Find the minimum total cost to turn all digits into .
Input
; a cost matrix; then the wall.
Output
Print the minimum total cost.
Subtasks
- Subtask 1 (40 points): , ; ; ; ; .
- Subtask 2 (60 points): ; ; ; .
Examples
Input
1 3
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 2 0 9 9 9 9 9 9 9
9 9 1 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 9
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 9 9 9 9 0 9
9 9 9 9 9 9 9 9 9 0
3 1 -1
Output
3
Explanation
Digit can become for and then for , totaling . Digit costs nothing and the empty cell is ignored.