Maximum Product Subarray, maximumsubarray

Source: Internet
Author: User

Maximum Product Subarray, maximumsubarray
Original question link: https://oj.leetcode.com/problems/maximum-product-subarray/
This question is similar to the Maximum Subarray model and the idea. It is still the "local optimization and global optimization" method in one-dimensional dynamic planning ". The difference here is that maintaining a local optimum is not enough to obtain the Global Optimum. This is because the multiplication is not as good as addition, and the accumulation result must increase progressively as long as it is positive, multiplication may be a negative number that seems to be small now, and then multiply it with another negative number to get the maximum product. But in fact, there is no much trouble. We only need to maintain a local maximum while maintaining a local minimum, so if the next element encounters a negative number, it is possible to obtain the Product Sum of the current maximum by multiplying the minimum value, which is also obtained by multiplication. The Code is as follows:

public int maxProduct(int[] A) {    if(A==null || A.length==0)        return 0;    if(A.length == 1)        return A[0];    int max_local = A[0];    int min_local = A[0];    int global = A[0];    for(int i=1;i<A.length;i++)    {        int max_copy = max_local;        max_local = Math.max(Math.max(A[i]*max_local, A[i]), A[i]*min_local);        min_local = Math.min(Math.min(A[i]*max_copy, A[i]), A[i]*min_local);        global = Math.max(global, max_local);    }    return global;}
This is a very good interview question, because Maximum Subarray is too common, so most people may have done it. This model is similar, but there are some new test sites, in addition, it is relatively simple in general. Both in terms of thinking and implementation, we can also examine dynamic planning, which is personally preferred.
Product of dimensions is greater than maximum integer

I don't know under what circumstances you have this. The literal meaning is "the product size exceeds the maximum integer ."

When an angry bird appears, texture is too large: 2048x2048, maximum supported size 1024x1024, how can this problem be solved?

Parts
Adjust width =? Height =?
You can
You can drag it with the mouse!
Product = "Angry Birds"
Publisher = "Rovio"
Name = "Angry Birds"
Width = 1024
Height = 600
Orientation = 0
Datapath = "data"
ImagePath = "images/pc_build"
FontPath = "fonts/pc_build"
AudioPath = "audio"
LocalizationPath = "localization"
LevelPath = "levels"
ScriptPath = "scripts"
DeviceModel = "windows"
Fullscreen = false
ShowCursor = false

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.