原题题目
代码实现(首刷)
int minSumOfLengths(int* arr, int arrSize, int target){
int dp[1001][1001],i,j,end,start,min1 = INT_MAX,min2 = INT_MAX,endpos1 = -1,startpos1 = -2,endpos2 = -3,startpos2 = -4,temp;memset(dp,0,sizeof(dp));for(end=0;end<arrSize;end++){
for(start=end;start>=0;start--){
if(start == end) dp[start][end] = arr[end];else dp[start][end] = dp[start+1][end] + arr[start];/*if(dp[start][end] == target){temp = end - start + 1;if(temp < min1 || temp < min2){if(min1 == INT_MAX || (min1 != INT_MAX && min2 !=INT_MAX) && (temp < min1 &&(start > endpos2 || end < startpos2))){min1 = temp;endpos1 = end;startpos1 = start;}else if(temp < min2 && (start > endpos1 || end < startpos1) ){min2 = temp;endpos2 = end;startpos2 = start;}}}*/}}if(min1!= INT_MAX && min2 != INT_MAX) return min1+min2;else return -1;
}