HDU5280 Senior ' s Array (simple DP)

Source: Internet
Author: User

Topic Link: Portal

Test instructions

Given a sequence of length n, and a modified value p, you must select a position from the original sequence to change to P,

The maximum value of the modified interval and.

Analysis:

Enumeration position + maximum interval and. Complexity O (n^2);

The code is as follows:

#include <iostream> #include <cstring> #include <cstdio> #include <algorithm>using namespace Std;typedef Long Long ll;const int MAXN = 1010;const LL inf = 1e15+10; LL A[MAXN],B[MAXN]; LL Dp[maxn];int Main () {    int t,n,p;    scanf ("%d", &t);    while (t--) {        scanf ("%d%d", &n,&p);        for (int i=0;i<n;i++) scanf ("%i64d", a+i);        LL ans =-inf;        for (int i=0;i<n;i++) {for            (int j=0;j<n;j++) {                if (j==i) b[j]=p;                else b[j]=a[j];                DP[J]=B[J];            }            for (int j=1;j<n;j++) {                Dp[j]=max (dp[j-1]+b[j],dp[j]);                Ans=max (Ans,dp[j]);            }        }        printf ("%i64d\n", ans);    }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU5280 Senior ' s Array (simple DP)

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.