Mr. Panda and Typewriter
시간 제한10초메모리 제한512 MB
문자 하나 추가, 부분 문자열 복사, 클립보드 붙여넣기 세 연산으로 정수 배열 S를 만들 때 드는 최소 시간을 구한다.
문제
Mr. Panda recently got a brand-new typewriter as a birthday gift from Mr. Champion. Mr. Panda likes the typewriter so much. He wants to use it to type a thank you letter and mail it to Mr. Champion.
To type the thank you letter, Mr. Panda starts with an empty string on a white-paper, and the following operations are allowed to perform by using the typewriter:
- Spend units of time to add any single character to the end of Mr. Panda's string.
- Spend units of time to copy any substring of Mr. Panda's string (that is, all of the sequential characters between some start point and some end point in Mr. Panda's string) to the clipboard. Doing this overwrites whatever was in the clipboard before. The clipboard starts off empty.
- Spend units of time to add the entire contents of the clipboard to the end of Mr. Panda's string. (The contents of the clipboard do not change.)
Mr. Panda needs to make his string exactly the same as the contents in the thank you letter . Note that Mr. Panda must create exactly the thank you letter with no additional character.
Mr. Panda wants to find a way to type the thank you letter with the minimum amount of spent time. Because Mr. Panda is too lazy, he asks for your help.
Could you please help Mr. Panda find an optimized way to type the thank you letter so that the amount of time spent is minimized? Note that you just need to tell Mr. Panda the minimum number of time units that are needed.
입력
The first line of the input gives the number of test cases (). test cases follow.
Each test case starts with a line consisting of four integers (), the length of Mr. Panda's thank you letter, , and (). , and are the time cost of operations that can be performed by the typewriter.
Then, a line consisting of integers , , , follows, denoting the contents of Mr. Panda's thank you letter. Each integer () represents a single character in the letter.
It is guaranteed that in at least 80% of test cases.
출력
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from ) and y is the minimum number of time units that are needed to type the thank you letter.