아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Mr. Panda and Typewriter

시간 제한10초메모리 제한512 MB

요약
문자 하나 추가, 부분 문자열 복사, 클립보드 붙여넣기 세 연산으로 정수 배열 S를 만들 때 드는 최소 시간을 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 문자열 매칭, 해시맵
정답자
아직 제출이 없습니다

문제

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 SS 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 XX units of time to add any single character to the end of Mr. Panda's string.
  • Spend YY 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 ZZ 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 SS. 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 TT (1≤T≤1001 \le T \le 100). TT test cases follow.

Each test case starts with a line consisting of four integers nn (1≤n≤50001 \leq n \leq 5000), the length of Mr. Panda's thank you letter, XX, YY and ZZ (1≤X,Y,Z≤1091 \leq X, Y, Z \leq 10^{9}). XX, YY and ZZ are the time cost of operations that can be performed by the typewriter.

Then, a line consisting of nn integers S_0S\_{0}, S_1S\_{1}, …\ldots, S_n−1S\_{n-1} follows, denoting the contents of Mr. Panda's thank you letter. Each integer S_iS\_{i} (1≤S_i≤1091 \leq S\_{i} \leq 10^{9}) represents a single character in the letter.

It is guaranteed that n≤1000n \leq 1000 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 11) and y is the minimum number of time units that are needed to type the thank you letter.

예제1

  1. 예제 1

    입력
    2
    6 1 1 1
    1 2 3 1 2 3
    6 10 8 8
    1 2 2 1 2 3
    
    예상 출력
    Case #1: 5
    Case #2: 56