字符串练习题:H - Another String Game

本文介绍了一个有趣的字符串游戏,其中Bob需要通过一系列操作使他的字符串与Alice的字符串相匹配。游戏涉及选择前缀、连接字符串副本及删除后缀等操作,并需最小化总成本。文章详细解释了输入输出格式及样例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

来源:Sichuan State Programming Contest 2014 Final

H - Another String Game

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

Bob and Alice like playing games together. Today, they come up with a new string game.

The rule of this game is like the following statement:

Initially, Alice has a string A . Then Bob can choose a prefix of string A as his initial string B and pay a cost equals the length of his initial string B multiplied by X . (for example: if Alice's string is abc, then Bob can choose a and pay X cost, or choose ab and pay 2×X cost, or choose abc and pay 3×X cost)

After that,Bob can perform the following two operations:

Operation I: Connect a copy of his string after his string, and pay a cost equals Y . (for example: after performing operation 1 Bob can change ab to abab or change aac toaacaac).

Operation II: Delete a suffix of his string, and pay a cost equals Z .(for example: after performing operation 2 Bob can change abcd to a, ab, or abc).

When Bob's string is the same as Alice's string, the game is end.Now, Bob wonders what's the minimum total cost he must pay after the end of the game?

Input

There is an integer T in the first line, indicates the number of test cases.

For each case, the first line contains a string A , which is Alice's string, it only contains lowercase letters.

The second line contains three integer X , Y , Z , as mentioned in the description.

1T60

1|A|105

1X,Y,Z10

Output

For each test, output "Case #i: " first, i is the case number, from 1 to T . Then output an integer in one line, which is the minimum cost Bob must pay.

Sample input and output

Sample InputSample Output
3
abcab
1 2 4
abcab
2 2 1
aaaaaaaa
1 1 1
Case #1: 5
Case #2: 9
Case #3: 4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值