注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
沒刷很多題, 我自己轉換題目的意思,或許地裡已經有了.
P1
Given:- A string S of length L.
- An offset array O where O[i] is the index in S that should be replaced with.
- An integer M.
In each round i, replace S[O[i]] with. Determine the minimum number of rounds required such that the number of substrings of S containing at least oneis greater than or equal to M.
Example:- S =
- O = [1, 2, 0, 3, 4]
- M = 10
Rounds:- Round 0: S =, Substrings containing: 8
- Round 1: S =, Substrings containing: 11
- Round 2: S =
- Round 3: S =[ DISCUZ_2, 4]
- D = [2, 2, 1]
- V = [1, 2, 3]
Explanation:- The time intervals are [1, 3], [2, 4], [4, 5].
- The second task overlaps with both the first and third tasks.
- The best way is to take the 1st and 3rd tasks.
- The total volume is 1 + 3 = 4.
Output:
第一題用DP不過要先把數字排序一下替換成索引,DP才不用浪費空間.
第二題第i個加入時, 只需要考慮離他最近左右兩邊的位置,新的包含的子串=當前子串數量+只包含新出現的星(i-l)*(r-i). |