Array single Harmonic

Source: Internet
Author: User

Time limit: 3 seconds Space limit: 32768K heat Index: 7374 The topic of knowledge points: Find dynamic Programming Title description

The sum of the array monotone and the F (i) values for all element I are now defined. The f (i) function here is defined as the sum of the numbers that are less than or equal to the left side of element I (excluding itself). Please design an efficient algorithm to calculate the monotony of the array.

Given an array of size nfor the given array, return the monotone of the array. Ensure that the array size is less than or equal to 500, while guaranteeing monotonic and not exceeding the int range.

Test examples:
[1,3,5,2,4,6],6
Returns: 27
1 classMonosum {2  Public:3     intCalcmonosum (vector<int> A,intN) {4         //Write code here5         intsum =0; 6          for(intI=1; i<n; i++)  7         {  8            intfi =0; 9             for(intj=0; j<i; J + +)  Ten                if(a[j]<=A[i]) Onefi+=A[j];  ASum + =fi;  -         }   -         returnsum;  the     } -};

Array single Harmonic

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.