当前位置:网站首页>[Dynamic programming] Maximum sum of consecutive subarrays
[Dynamic programming] Maximum sum of consecutive subarrays
2022-07-31 03:10:00 【#baking soda】
Dynamic programming (DP): Each state in dynamic programming must be derived from the previous state, which is different from greed, which has no state derivation, but selects the optimal from the local.
Dynamic programming problem solving steps

1: Determine the dp array, dp[ i ] is the maximum consecutive subsequence sum before subscript i.
2: Determine the state transition equation, dp[ i ] has two directions, dp[ i-1 ]+nums[ i ] is adding the current continuous subsequence sum,
num[ i ] is the sum of subsequences to index i calculated from scratch.
3: Initialize dp array, this topic can see that dp[ i ] depends on dp[ i-1 ], so dp[ 0 ] is the basis of recursive company.
4: Determine the traversal order, this question needs to be traversed from front to back.
class Solution {public int maxSubArray(int[] nums) {int[] dp = new int[nums.length];dp[0] = nums[0]; //Initialize dpint max = dp[0]; // output the maximum value as an intermediate variablefor(int i = 1;i边栏推荐
猜你喜欢

Moxa NPort device flaw could expose critical infrastructure to devastating attack

Use of QML

【C语言】三子棋(经典解法+一览图)

学习DAVID数据库(1)

大小端模式

Local area network computer hardware information collection tool

The use of font compression artifact font-spider

SQL injection Less54 (limited number of SQL injection + union injection)

数据库实现分布式锁

Multilingual settings of php website (IP address distinguishes domestic and foreign)
随机推荐
Local area network computer hardware information collection tool
Mysql 45讲学习笔记(二十五)MYSQL保证高可用
Ambiguous method call.both
PMP微信群日常习题
5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
return in try-catch
execsnoop tool
web容器及IIS --- 中间件渗透方法1
递归查询单表-单表树结构-(自用)
[Godot][GDScript] 2D cave map randomly generated
The Map Entry understanding and application
字体压缩神器font-spider的使用
JetPack component Databinding
原子操作 CAS
数据库实现分布式锁
YOLOV5 study notes (2) - environment installation + operation + training
YOLOV5学习笔记(三)——网络模块详解
Moxa NPort device flaw could expose critical infrastructure to devastating attack
11. Redis implements follow, unfollow, and follow and follower lists
15、网站统计数据