Problem Statement
有 N 门课,每门课有 Level 0 ~ Level 9,
一开始你会每门课的 0 级,有 M 种训练,
每种训练可以描述为 “在你学会了 A 的 Level B 之后,可以花 T 的时间学会 C 的 Level D”,
当然,当你某门课学会了某个等级,那么这门课之前的等级都可以视为学会,
问所有课到达 9 级的最短时间,或说明不可能.
N <= 9
M <= 200
Fox Ciel plans to learn n new foreign languages because she is such a clever fox. The languages are named with characters 'A', 'B', ..., 'A'+n-1. For each language, there are ten levels of fluency from 0 to 9. Fox Ciel starts out with fluency 0 in every foreign language. Level 9 denotes mastery of the language.
A number of language courses are available to Fox Ciel. Each course has a prerequisite language and level, and it leads to a target language and level. The prerequisite language is not necessarily the same as the target language. Each course also takes a certain amount of time.
A course is described by the String[] courseInfo. Concatenate all of the Strings to obtain a single String that looks like this:
"B9->C2:0200 A0->A9:1000 A3->A4:0001"
Note that the number after the colon (':') is always four digits long. The example above contains three courses. The first one is described as "B9->C2:0200", which means that if Fox Ciel has achieved a fluency of no less than 9 in language B, she can spend 200 hours in this course to achieve a fluency of exactly 2 in language C.
How much time must Fox Ciel spend to master (i.e., reach level 9 in) every language? Return the minimal number of hours, or return -1 if it is not possible for her to master every language.