3864. Minimum Cost to Partition a Binary String
You are given a binary string
sand two integersencCostandflatCost.For each index
i,s[i] = '1'indicates that thei^thelement is sensitive, ands[i] = '0'indicates that it is not.The string must be partitioned into segments. Initially, the entire string forms a single segment.
For a segment of length
LcontainingXsensitive elements:
- If
X = 0, the cost isflatCost.- If
X > 0, the cost isL * X * encCost.If a segment has even length, you may split it into two contiguous segments of equal length and the cost of this split is the sum of costs of the resulting segments.
Return an integer denoting the minimum possible total cost over all valid partitions.
1 | int pre[101010]; |