
Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
History is littered with hundreds of conflicts over the future of a community, group, location or business that were "resolved" when one of the parties stepped ahead and destroyed what was there. With the original point of contention destroyed, the debates would fall to the wayside. Archive Team believes that by duplicated condemned data, the conversation and debate can continue, as well as the richness and insight gained by keeping the materials. Our projects have ranged in size from a single volunteer downloading the data to a small-but-critical site, to over 100 volunteers stepping forward to acquire terabytes of user-created data to save for future generations.
The main site for Archive Team is at archiveteam.org and contains up to the date information on various projects, manifestos, plans and walkthroughs.
This collection contains the output of many Archive Team projects, both ongoing and completed. Thanks to the generous providing of disk space by the Internet Archive, multi-terabyte datasets can be made available, as well as in use by the Wayback Machine, providing a path back to lost websites and work.
Our collection has grown to the point of having sub-collections for the type of data we acquire. If you are seeking to browse the contents of these collections, the Wayback Machine is the best first stop. Otherwise, you are free to dig into the stacks to see what you may find.
The Archive Team Panic Downloads are full pulldowns of currently extant websites, meant to serve as emergency backups for needed sites that are in danger of closing, or which will be missed dearly if suddenly lost due to hard drive crashes or server failures.
We are given an array
A
ofN
lowercase letter strings, all of the same length.Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices.
For example, if we have an array
A = ["babca","bbazb"]
and deletion indices{0, 1, 4}
, then the final array after deletions is["bc","az"]
.Suppose we chose a set of deletion indices
D
such that after deletions, the final array has every element (row) in lexicographic order.For clarity,
A[0]
is in lexicographic order (ie.A[0][0] <= A[0][1] <= ... <= A[0][A[0].length - 1]
),A[1]
is in lexicographic order (ie.A[1][0] <= A[1][1] <= ... <= A[1][A[1].length - 1]
), and so on.Return the minimum possible value of
D.length
.Example 1:
Example 2:
Example 3:
Note:
1 <= A.length <= 100
1 <= A[i].length <= 100
这道题说是给了一个字符串数组A,其中每个字符串的长度均相同,现在需要删除一些特定位置上的字符,需要使得留下的字符是按照字母顺序排列的,问最少需要删除多少列。这道题需要借助题目中给的例子来理解,因为每个字符串长度相同,若每行放一个字符串,那么其实也可以看作是一个二维的字符数组,要删除最少的列,使得每行都是有序的。实际上最差的情况就是每行都是倒序的,就要移除 n-1 列,只留下一列,若每行只有一个字符,则一定是符合题意。最好的情况就是给定每行已经都是有序的,则一列都不用移除,所以最终的结果是在一定的范围之内的,即 [0, n-1],其中n是字符串的长度。假如只有一个字符串,为了使其有序,需要移除最小的列数,移除之后剩下的就是有序的。那么其实就是等同于找出该字符串中的最大递增序列的长度,即之前那道 Longest Increasing Subsequence 的做法,然后用总长度减去这个 LIS 长度,即为最少移除的列数。若有多行的情况,这个 LIS 必须是所有行都满足的,才符合题意。这里维护一个一维 dp 数组,其中 dp[i] 表示以 A[][i] 为结尾的最长递增子串的长度,对于每一个 A[][i],从该行第一个数再搜索到i,此时由于有多行,每一行都要判断一下,假如出现 A[][j] 大于 A[][i] 的情况,说明当前列不能组成 LIS,直接 break。只有每行都符合要求,并且 dp[j]+1 大于 d[i] 时,将 dp[i] 赋值为 dp[j]+1。当每次 dp[i] 更新了之后,用 n-dp[i] 来更新结果 res 即可,参见代码如下:
讨论:可能会有同学有疑问,会出现 dp[j]+1 小于 dp[i] 的情况么,其实是有的,比如 "cbbdabc",i = 6,是最后一个c,因为前面有前面出现了 bb,所以此时的 dp[6] = 3,当 j = 4 时,是中间的a,前面没有比a小的字母,所以 dp[4] = 1,此时就出现了 dp[j]+1 小于 dp[i] 的情况。
Github 同步地址:
#960
类似题目:
Longest Increasing Subsequence
Delete Columns to Make Sorted
Delete Columns to Make Sorted II
参考资料:
https://leetcode.com/problems/delete-columns-to-make-sorted-iii/
https://leetcode.com/problems/delete-columns-to-make-sorted-iii/discuss/206861/C%2B%2B-7-lines-DP-O(n-*-n-*-m)
https://leetcode.com/problems/delete-columns-to-make-sorted-iii/discuss/205679/C%2B%2BJavaPython-Maximum-Increasing-Subsequence
LeetCode All in One 题目讲解汇总(持续更新中...)
The text was updated successfully, but these errors were encountered: