随笔分类 - DP
摘要:You are given weights and values of N items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. Note that we
阅读全文
摘要:给你一个字符串 s ,每一次操作你都可以在字符串的任意位置插入任意字符。 请你返回让 s 成为回文串的 最少操作次数 。 「回文串」是正读和反读都相同的字符串。 示例 1: 输入:s = "zzazz"输出:0解释:字符串 "zzazz" 已经是回文串了,所以不需要做任何插入操作。示例 2: 输入:
阅读全文
摘要:X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. Each digit must be rotate
阅读全文
摘要:Given two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one cha
阅读全文
摘要:A string of '0's and '1's is monotone increasing if it consists of some number of '0's (possibly 0), followed by some number of '1's (also possibly 0.
阅读全文
摘要:There are N piles of stones arranged in a row. The i-th pile has stones[i] stones. A move consists of merging exactly K consecutive piles into one pil
阅读全文
摘要:A subarray A[i], A[i+1], ..., A[j] of A is said to be turbulent if and only if: For i <= k < j, A[k] > A[k+1] when k is odd, and A[k] < A[k+1] when k
阅读全文
摘要:You are given an integer array A. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, ...) jumps in the series are called od
阅读全文
摘要:Given a string S, count the number of distinct, non-empty subsequences of S . Since the result may be large, return the answer modulo 10^9 + 7. Exampl
阅读全文
摘要:A chess knight can move as indicated in the chess diagram below: . This time, we place our chess knight on any numbered key of a phone pad (indicated
阅读全文
摘要:Given a square array of integers A, we want the minimum sum of a falling path through A. A falling path starts at any element in the first row, and ch
阅读全文
摘要:Your music player contains N different songs and she wants to listen to L (not necessarily different) songs during your trip. You create a playlist so
阅读全文
摘要:We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}. (Note that '0' is not included.) Now, we write numbers
阅读全文
摘要:We have an array A of non-negative integers. For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of al
阅读全文
摘要:You are given K eggs, and you have access to a building with N floors from 1 to N. Each egg is identical in function, and if an egg breaks, you cannot
阅读全文
摘要:There are G people in a gang, and a list of various crimes they could commit. The i-th crime generates a profit[i] and requires group[i] gang members
阅读全文
摘要:A sequence X_1, X_2, ..., X_n is fibonacci-like if: n >= 3 X_i + X_{i+1} = X_{i+2} for all i + 2 <= n Given a strictly increasing array A of positive
阅读全文
摘要:There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to t
阅读全文
摘要:We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the sum of the average of each group. What is the larges
阅读全文
摘要:We have two integer sequences A and B of the same non-zero length. We are allowed to swap elements A[i] and B[i]. Note that both elements are in the s
阅读全文