最大子数组
#include<iostream>
#include <time.h>
#include<climits>
using namespace std;
int maxSubset(int a[], int low, int high)
{
int temp = 0, sum = INT_MIN;
for (int i = low; i <= high; i++)
{
temp += a[i];
if (temp > sum) sum = temp;
if (temp < 0) temp = 0;//遍历寻找要求的划分块
}
return sum;
}
int main()
{
int a[] = { -13, -3, -25, -20, -3, -16, -23, -18, -20, -7, -12, -5, -22, -15, -4, -7 };
int length = sizeof(a) / sizeof(int);
cout << "the maxsubset:" << maxSubset(a, 0, 15) << endl;
system("pause");
}