学会背包问题,再也不怕动态规划 0-1背包

问题描述 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. In other words, given two integer arrays val[0..n-1] and wt[0..n-1] which represent values and weights associated with n items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item, or don’t pick it (0-1 property). ...

August 23, 2020

leetcode-53. Maximum Subarray

题目 leetcode-53. Maximum Subarray 类似: leetcode-152. Maximum Product Subarray 要点是记录当前最大值,与最小值。 计算当前最值有三种可能: 当前值 前一个最大值与当前值之积 前一个最小值与当前值之积 从这三种取出最小值和最大值。 (从三个可能优化到两个) ...

July 18, 2018

DFS与BFS适用场景

背景 Depth-First-Search(DFS)深度优先搜索与Breadth-First Search(BFS)广度优先搜索是树与图中最常用的算法。 ...

August 23, 2017