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)