Topic:
?
Test Instructions: The maximum value of the number of successive subsequence sequences in the given sequence, and the starting and ending points of this subsequence.
idea:DP to find the maximum value of the current position,dp[i] = max (dp[i-1], a[i]); The position of the maximum is the end point, since you know the sum of the size, then, just find the sum of that interval is the value can be, here you can use a prefix and array to find the starting position.
PS:DP still have to think more, practise more!!
Code:
1#include <iostream>2#include <queue>3#include <cstdio>4#include <algorithm>5#include <cmath>6#include <cstring>7#include <queue>8#include <map>9#include <vector>Ten #defineINF 0x3f3f3f3f One #defineFRE () freopen ("In.txt", "R", stdin) A - using namespacestd; -typedefLong Longll; the Const intMAXN = 1e5+Ten; - intA[MAXN],DP[MAXN],SUM[MAXN]; - intMain () - { + intt,n,cnt =1; -scanf"%d",&T); + while(t--) A { atMemset (A,0,sizeof(a)); -Memset (DP,0,sizeof(DP)); -memset (SUM,0,sizeof(sum)); -scanf"%d",&n); - for(inti =1; i<=n; i++) - { inscanf"%d",&a[i]); -Sum[i] = sum[i-1]+A[i]; to } + intSt =0, en =0, Mmax =-inf,f =1; - for(inti =1; i<=n; i++) the { *Dp[i] = max (dp[i-1]+a[i],a[i]); $ if(dp[i]>Mmax)Panax Notoginseng { -Mmax =Dp[i]; theEn =i; + } A } the for(inti =1; i<=en; i++) + { - if(sum[en]-sum[i-1] ==Mmax) $ { $St =i; - Break; - } the } - if(cnt!=1) printf ("\ n");Wuyiprintf"Case %d:\n", cnt++); theprintf"%d%d%d\n", mmax,st,en); - } Wu return 0; - } About $ /* - Sample Input: - 2 - 5 6-1 5 4-7 A 7 0 6-1 1-6 7-5 + Sample output: the Case 1: - 1 4 $ the Case 2: the 7 1 6 the */
View Code
MAX SUM (HDU_1003--DP)