PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000081. Đổi xâu chi phí nhỏ nhất I (Minimum Cost to Convert String I)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đổi xâu chi phí nhỏ nhất I (Minimum Cost to Convert String I)
Minimum Cost to Convert String I
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given equal-length lowercase source and target strings and positive-cost single-character transformation rules, find the minimum total cost to convert source into target using zero or more intermediate transformations, or -1.
Input
Input has source string , target string , then and directed rules from to cost.
Output
Print the minimum conversion cost or -1.
Subtasks
-
Subtask 1 (40 points): . Chỉ dùng chữ thường
a–z; ; mọi quy tắc có hướng. -
Subtask 2 (60 points): . Chỉ dùng chữ thường
a–z; ; mọi quy tắc có hướng.
Examples
Input
ab
cc
3
a b 3
b c 2
a c 10
Output
7
Explanation
Converting a to c through b costs 5; converting the second b to c costs 2. The total is 7.