Logo
(追記) (追記ここまで)

11106번 - Free Willy 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 256 MB47161140.741%

문제

Willy is sitting behind bars in Alcatraz. Jan Erik Vold is guarding him, and gives him a challenge:

”I managed to transform KULTURUKE into UKTURKULE by applying these permutations in succession: bcdefaghi cabfdeghi bcadefghi adcefgbhi cgabdefhi cdaefhgbi

That’s what gave me the start of my great poem: KULTURUKE ULTURKUKE TULKURUKE ULTKURUKE UKTURULKE TLUKURUKE UKTURKULE

Now, I want you to do the transformation using the same set of available permutations. I permuted 6 times, but if you can manage to do it by permuting fewer times than I did, then I’ll unlock the cage!”

”That’s easy, I only need 4 permutations!” says Willy ”You first apply bcadefghi to get ULKTURUKE. Then cdaefhgbi to get KTUURKULE. Then bcadefghi again to get TUKURKULE. And finally bcadefghi a third time to get UKTURKULE.”

”Oh, you’re not a big, dumb fish after all” says Jan Erik and brings out the keys. Willy jumps into the ocean and lives happily ever after!

입력

The first line of the input gives the number of test cases T ≤ 30. The first line of each test case contains 1 ≤ N ≤ 26, 1 ≤ P ≤ 10, and 1 ≤ L ≤ 10. The second line contains two words with N characters each. Then follow P lines, each with an allowed permutation of the first N letters of the alphabet (in lowercase).

출력

For each test case, output one line with the minimum number of times you need to apply one of the allowed permutations to the letters of the first word in order to arrive at the second word, or “whalemeat” if it’s not possible to do it in at most L steps.

제한

예제 입력 1

3
9 6 5
KULTURUKE UKTURKULE
bcdefaghi
cabfdeghi
bcadefghi
adcefgbhi
cgabdefhi
cdaefhgbi
9 5 4
kulturuke tlukuruke
bcdefaghi
cabfdeghi
bcadefghi
adcefgbhi
cgabdefhi
9 3 4
WILLFREEY FREEWILLY
bacdefghi
abghefdic
fecdbaigh

예제 출력 1

4
whalemeat
4

힌트

출처

Contest > IDI Open Contest > IDI Open 2007 I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /