线性规划

来源:互联网 发布:空间数据库怎么弄 编辑:程序博客网 时间:2024/06/04 08:26

最大子数组

#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");}

0 0
原创粉丝点击