注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
本帖最后由 kenpeter 于 2024-12-9 18:25 编辑
这个是原题
It is a bit long, but I will summarise what is really asking.- test case 1:
- input1, bad phase in password:
- bcb (it can be rearranged as bbc, cbb)
- input2, password:
- abcdcbcb
- input3, operation cost:
- [a_2, b_3, c_1, d_4, e_0, f_0..... z_0] (rest are op cost zero)
- our goal is that we don't want bcb or b????c???b (subsequence) appearing in password. Same for bbc, cbb. We will remove each letter with cost and return the min total cost operation.
- may use stack, but I am not sure.
- abcdcbcb -> strip all unrelated chars -> bccbcb
- sample stack dry run
- run 1:
- bad phase:
- bcb
- bbc
- cbb
- [b]
- [bc]
- [bcc]
- [bccb_x] (+3)
- [bccc]
- [bcccb_x] (+3)
- total cost = 3+3=6
-
- run 2:
- bcb
- bbc
- cbb
- [b]
- [bc_x] (+1)
- [bc_x] (+1)
- [bc_x] (+1)
- [bb]
- [bbb]
- total cost = 1+1+1=3
-
- run 3:
- bcb
- bbc
- cbb
- [b_x] (+3)
- [c]
- [cc]
- [ccb]
- [ccbc]
- [ccbcb_x] (+3)
- total cost = 3+3=6
-
- so min cost 1+1+1=3 (not sure correctness, but you get the idea)
复制代码 我想问问代码如何写。 |