Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to find the maximum subarray product of C++

Shulou Source: shulou.com Published: 2022-05-31 23:15:27 09月24日 Update

This article introduces the knowledge of "how to find the maximum subarray product of C++". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The topic requires: given an array of integers, find the value of the subarray with the largest product.

# include # include # include using namespace std;/* maximum substring product, due to possible negative number. It is also a DP problem, as well as a local optimal problem and a global optimal problem. Here we need to record the minimum value. Suppose there are two arrays that record the maximum and minimum values that can be formed by substrings, including the current element, respectively, and then update the global maximum according to this. As for the current maximum, it may be the previous maximum multiplied by the current element, or the previous element minimum multiplied by the current element. It could also be the current element * / int maxProduct (vector& vec) {if (vec.size () = = 0) return 0 Vector maxcur (vec.size (), 0); vector mincur (vec.size (), 0); maxcur [0] = vec [0]; mincur [0] = vec [0]; int maxproduct = vec [0]; int itemp; for

Tags: Maximum array element product minimum cantilever global content more knowledge problem practical successful next two dilemma actual local situation integer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Shulou Tech Info MySQL Microsoft