Title: http://acm.hdu.edu.cn/showproblem.php?pid=1244
problem DescriptionGiven a sequence of integers consisting of n positive integers
A1 A2 A3 ... an
The maximum value of consecutive integers in which the length of M segment is L1, L2, L3...LM, respectively, is obtained in order of precedence.
InputThe first line is an integer n (0≤n≤1000), and n = 0 indicates the end of the input
The first number in the second row is M (1≤m≤20),
The second line is followed by a M integer l1,l2...lm.
The third line is n integers a1, a2, A2 ... an.
OutputThe maximum value of the output m segment integer and.
Sample Input32 1 11 2 342 1 21 2 3 50
Sample Output5 10
DFS + Memory
#include <cstdio>#include<iostream>#include<cstring>#include<string>#defineINF 0x3f3f3f3fusing namespacestd;inta[1005];intsum[1005];intl[ -];intdp[ -][1005];intN, M;intDfsintIintcur) { if(Cur > N)return-INF; if(i==m+1)return 0; if(Dp[i][cur])returnDp[i][cur]; intret=-INF; for(intK=cur; k<n; k++) {ret= MAX (ret, DFS (i+1, K+l[i]) +sum[k+l[i]]-Sum[k]); } returnDp[i][cur] =ret;}intMain () { while(SCANF ("%d", &n)! = EOF &&N) {scanf ("%d", &m); for(intI=1; i<=m; i++) {scanf ("%d", &L[i]); } for(intI=1; i<=n; i++) {scanf ("%d", &A[i]); Sum[i]= sum[i-1] +A[i]; } printf ("%d\n", DFS (1,0)); Memset (DP,0,sizeof(DP)); } return 0;}
HDU 2746--max Sum plus plus plus