BVAAN  Balika Vadhu and Alok Nath
Anandi and Jagya were getting married again when they have achieved proper age. Dadi Sa invited Alok Nath to do the kanyadaan and give blessings. Alok Nath has 2 blessings. Each bessing is in the form of a string consisting of lowercase charaters(az) only. But he can give only one blessing of K length because some priest told him to do so. Thus he decides to generate a blessing using the other two blessings. While doing this he wants to ensure that happiness brought into their life by his blessing is maximum.
The generated blessing is a common subsequence of length K of the two blessings he has. Happiness of the blessing he generates is calculated by the sum of ASCII values of characters in the blessing and he wants the happiness to be maximum. If he is not able to generate a common subsequence of length K then the happiness is 0 (zero). Alok Nath comes to you and asks you to find the maximum happiness that can be generated by the two blessings he has.
Input Specification
First line consists of number of test cases t. Each test case consists of two strings b1 (blessing 1),b2 (blessing 2) and an integer K, each of them in separate lines.
Output Specification
Output consists of t lines each containing an integer denoting the maximum happiness value that can be generated by the two blessings.
Constraint
1 <= t <= 50
1 <= length(b1) , length(b2) <= 100
1 <= K <= 100
Sample Input
2
asdf
asdf
3
anandi
jagya
3
Sample Output
317
0
hide comments
kira28:
20161227 14:27:07
Very good ques!!!


siddharth_0196:
20161016 19:31:28
Any corner cases?


Riddhi:
20160611 15:35:53
i\p


SUBHAM SANGHAI:
20160524 09:33:35
@silverscar Try this test case :


karthik1997:
20160106 13:21:03
If the lcs is less than k , ouput is 0


vagisha:
20160102 14:23:16
Nice combination of LCS and Knapsack :) 

anshal dwivedi:
20160102 09:18:50
yo papi!!! 200th of mine :) XD 

alpha coder:
20151208 18:13:23
gives the feel of recursion ! ;) 

silverscar:
20151207 08:57:56
Instead of doing it in O(nmk) I tried it by doing standard lcs, backtrack to get back the lcs string, reverse sort the string and add the values of the first k characters in the string. Please tell me what's wrong with my logic...!! 

dkumarsingh:
20151203 20:53:15
i'm getting wrong answer for my submission id 15772416 can u please tell me for which test cases my answer is wrong 
Added by:  Sanket Singhal 
Date:  20150218 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: JS2 
Resource:  Own Problem(CQM 8 BIT Mesra) 