3. String Hopping

3

2 votes
Medium, DP
Problem

Given a string and the cost associated with every index, you are to find a subsequence "abcdefghijklmnopqrstuvwxyz" with minimum total cost. The total cost is the summation of all the chosen indexes. Print "Not Possible." if the subsequence is not found.

(A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.)

Constraints : 1<=t<=10
1<=|str|<=10000
1<=cost associated with every index<=100

input format :
t - number of test cases.
2*t lines follow
first line contains the string
second line contains the cost associated with every index of the string

output format :
print the minimum cost,else "Not Possible." for each test case in a new line

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?