SRM 624 Building Heights DivI Interpretation

Source: Internet
Author: User

Almost the same title. For more information, see: http://community.topcoder.com/stat?c=problem_statement&pm=13211&rd=15857

Thinking:

1 sequence

2 calculation of the current number of buildings I, all possible minimum building changes

3 each time the calculation i+1. Total possible minimum number of building changes

4 minimum number of changes when you can get i+1 at the same time

And the procedures are not complicated.

#include <vector> #include <algorithm> #include <limits.h> #include <math.h>using namespace std ; Class Buildingheights{public:int minimum (vector<int> heights) {int n = (int) heights.size (); Sort (Heights.begin ( ), Heights.end ());vector<int> cost (n, 0); int ans = 0;for (int i = 0; i < n-1; i++) {int c = int_max;for (int j = n -1; J > i; j--) {Cost[j] = Cost[j-1] + (heights[j]-heights[j-1]) * (i+1); c = min (c, cost[j]);} Ans ^= c;} return ans;};



Copyright notice: The author Heart Jing, Jing Space address: http://blog.csdn.net/kenden23/, may not be reproduced without the consent of the author.

SRM 624 Building Heights DivI Interpretation

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.