Enter a set of integers to find out the set of number sub-sequences and the maximum values. That is, only the maximum number of sub-sequences is required, and the largest sequence is not to be obtained. For example:
Sequence:-2 11-4 13-5-2, the maximum subsequence and 20.
Sequence:-6 2 4-7 5 3 2-1 6-9 10-2, the maximum subsequence and 16
#include <stdio.h>
int main ()
{
void res (int num[],int n);
int n;
while (scanf ("%d", &n)!=eof)
{
int num[110],i;
for (i=0;i<n;i++)
scanf ("%d", &num[i]);
Res (NUM,N);
}
return 0;
}
void res (int num[],int N)
{
int i,sum=0,max=0;
for (i=0;i<n;i++)
{
Sum=sum+num[i];
if (Sum>max)//continuous and larger than Max, assign to Max
Max=sum;
if (sum<0)//If consecutive numbers and becomes negative, then the next number larger than Max will be added from this number
sum=0;
}
printf ("%d\n", Max);
}
Maximum continuous and--DP