字符串练习题:H - Another String Game
2015-02-07 21:43
295 查看
来源:Sichuan State Programming Contest 2014 Final
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
cost, or choose
cost, or choose
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 equalsY.
(for example: after performing operation 1
Bob can change
Operation II: Delete a suffix of his string, and pay a cost equals
Z.(for
example: after performing operation 2
Bob can change
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?
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.
1≤T≤60
1≤|A|≤105
1≤X,Y,Z≤10
is the case number, from 1
to T.
Then output an integer in one line, which is the minimum cost Bob must pay.
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
aand payX
cost, or choose
aband pay 2×X
cost, or choose
abcand 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 equalsY.
(for example: after performing operation 1
Bob can change
abto
ababor change
aacto
aacaac).
Operation II: Delete a suffix of his string, and pay a cost equals
Z.(for
example: after performing operation 2
Bob can change
abcdto
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 Tin 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.
1≤T≤60
1≤|A|≤105
1≤X,Y,Z≤10
Output
For each test, output "Case #i: " first, iis 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 Input | Sample Output |
---|---|
3 abcab 1 2 4 abcab 2 2 1 aaaaaaaa 1 1 1 | Case #1: 5 Case #2: 9 Case #3: 4 |
相关文章推荐
- java编程---3.2 (关于String的练习题) 统计字符串中每个字符的个数,例如:把aaaabbaaccbb变成a6b4c2
- java学习之路 之 Java常用类-字符串(String)类及练习题
- Hash练习题:【HDOJ4821】--String【字符串hash】
- java编程---3.3 (关于String/for的练习题) 提取字符串中连续相同的字符,例如:把aabbaaccbbbm变成2a2b2a2c3bm
- java编程---3.1 (关于String的练习题) 将字符串中的字符按需求等分,例如:把aqzxswerdcvfr变成AQZX-SWER-DCVF-R
- 使用System.StringSplitOptions去除待拆分字符串中的空项
- C++/CLI 中字符串类型的转化: 把std::string转化为System::String
- 计算一个字符串string包含特定子串的数量(转载)
- std::stringstream只适合作字符串格式化
- Symbian-Descriptor/String 字符串相关
- 字符串转换系列二:CString、CStringA 和 CStringW
- 字符串string 字符数组与指向字符串的指针pchar的区别与联系
- 小技巧(一)分离字符串string str="(1,10,100,1000,10000,)";
- C# 格式化字符串 String.Format (http://blog.soease.com/andy/)
- [原创]捕捉 OutputDebugString 输出的字符串
- C# string格式的日期时间字符串转为DateTime类型的方法
- 使用System.Convert.ToString将字符串转换成utf16进制编码
- javascript入门·js核心语言--字符串(string)
- 增强J2ME的String能力——分割字符串(附源代码)
- [原创]捕捉 OutputDebugString 输出的字符串