作业帮 > 综合 > 作业

C语言求max Problem DescriptionGiven a sequence a[1],a[2],a[3].a

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/12 11:04:58
C语言求max
Problem Description
Given a sequence a[1],a[2],a[3].a[n],your job is to calculate the max sum of a sub-sequence.For example,given (6,-1,5,4,-7),the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.
Input
The first line of the input contains an integer T(1
#include
#define SIZE 100000
using namespace std;
int main()
{
int arr[SIZE];//存放数组
long ori ; //前一次相加的最大记录
long now ; //当前最大
long max; //第i前n个数最大和
int from ; //标记
long to = 0,i,n,num;
int from_max,to_max;
cin>>num;
for(int j=0;j>n;
for(i=0;i>arr[i];
ori=arr[0];
now=arr[0];
max=arr[0];
from_max=from=1;
to_max=to=1;
for ( i=1; i