最大子序列和

来源:互联网 发布:stc单片机usb驱动下载 编辑:程序博客网 时间:2024/05/18 16:54
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int zdzdh(int* nums,int i)
{
if (i==0)
return nums[i];
else
{
if (nums[i] + zdzdh(nums, i - 1) < nums[i])
return nums[i];
else
return zdzdh(nums, i - 1)+nums[i];
}
}
int max_zdh(int* num,int len)
{
vector<int> temp;
int i = 0;
while (i <=len)
{
temp.push_back(zdzdh(num, i));
i++;
}
int re =*max_element(temp.begin(), temp.end());
return re;
}
int main()
{
int nums[] = { 0, -1, 3, -2, 4, 6, -4, 7, 5, -2 };
int re;
re=max_zdh(nums,2);
return 0;
}
原创粉丝点击