Dp FOJ September January-September C ytaaa

Source: Internet
Author: User

Dp FOJ September January-September C ytaaa

Accept: 57 Submit: 261
Time Limit: 2000 mSec Memory Limit: 32768 KB Problem DescriptionYtaaa executes countless difficult tasks as a special engineer. This Time, ytaaa receives commands and needs to blow up an enemy factory, ytaaa needs to create a batch of bombs for use. The new type of bomb used by Ytaaa is composed of several explosives, each of which has its power value, and the power value of the bomb is the square of the maximum power difference of all the explosives that make up the bomb, that is, (max-min) ^ 2. Assume that a bomb is composed of five explosives and its power is 5 9 8 2 1, respectively. Then its power is (9-1) ^ 2 = 64. Now there are n lines of explosives in the bomb manufacturing pipeline. Due to time constraints, ytaaa does not have time to change their order, so they can only determine their group. As the Chief Consultant of ytaaa, please help ytaaa determine the explosive group so that the bomb has the greatest power and power. Input is composed of multiple groups of data. The first behavior is a positive integer n (n <= 1000), and the second behavior is n, a [I] indicates the power of the I-th explosive (0 <= a [I] <= 1000 ). Output outputs a row of numbers for a given input, which is the sum of the maximum power of all bombs. Sample Input65 9 8 2 1 6 Sample Output77
Cached at 17:29:14.
Submit Back Status <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Vc3Ryb25nPgo8YnI + cjxwp?vcd4kpha + PHByZSBjbGFzcz0 = "brush: java; "> /************************************* * ***********************************> File Name: foj. cpp> Author: acvlinoleic> QQ:> Mail: acvcla@gmail.com> Created Time: ******************************** **************************************** /# include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include Using namespace std; typedef long LL; const int maxn = 1e3 + 10; # define rep (I, a, B) for (int I = (); I <= (B); I ++) # define pb push_backint A [maxn], n; int d [maxn] [maxn], MAX, MIN; int dp [maxn] [2]; int main () {while (~ Scanf ("% d", & n) {rep (I, 1, n) scanf ("% d", A + I); memset (d, 0, sizeof d); memset (dp, 0, sizeof dp); for (int I = 1; I <= n-1; I ++) for (int j = I; j <= n; j ++) {if (I = j) {MAX = MIN = A [I]; continue;} MAX = max (MAX, A [j]); MIN = min (MIN, A [j]); d [I] [j] = (MAX-MIN) * (MAX-MIN );} for (int I = 1; I <= n; I ++) {for (int j = I-1; j> = 1; j --) {dp [I] [0] = max (dp [I-1] [0], dp [I-1] [1]); dp [I] [1] = max (dp [I] [1], dp [j] [0] + d [j] [I]);} int ans = max (dp [n] [0], dp [n] [1]); printf ("% d \ n", ans);} return 0 ;}



Related Article

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.