染色
[[IntervalDP|IntervalDP]]
You are given an array of length consisting of non-negative integers.
You have another array of the same length. Initially, for all .
You can perform the following operation any number of times:
- Choose a non-negative integer and a subarray , then set for all .
Find the minimum number of operations required to transform the array into the target array .
Note that the target array may contain zeros.
给定数组 。
初始有一个全为 0 的数组,每次任选一个非负整数 ,任选一个区间 ,把区间 都变成 ,最少需要多少次得到目标数组? 目标数组可能包含 0。
第一步:不考虑 0,区间 DP
- 初始状态:
- 如果 ,
第二步:考虑 0,线性 DP
- 表示将初始全 0 数组的前缀 变为目标数组 的最少操作次数。
- 初始状态:
- 如果
- 最终答案:
本部落格所有文章除特別聲明外,均採用CC BY-NC-SA 4.0 授權協議。轉載請註明來源 小明の雜貨屋!
評論
