求整数序列最大面积

#include <stdio.h>

#define N 4

int fun(int *arr)
{
    int i,j;
    int x,y;
    int temp;
    int a[N];

    for(j = 0; j < N; j++)    
    {
        x = j;
        y = j;
        for(i = 0; i< x; i++)
        {
            if(x > 0)
            {
                if(arr[j]<arr[x-1])
                    x--;
                else break;
            }
        }
        for(i = y; i< N; i++)
        {
            if(y < N)
            {
                if(arr[j]<arr[y+1])
                    y++;
                else break;
            }
        }
        a[j] = (y-x+1)*arr[j];
    }
    
    temp = a[0];
    for(j = 0; j < N; j++)
    {
        if(a[j]>temp)
            temp = a[j];
    }
    return temp;
}


int main()
{
    //int arr[N] = {2,1,5,6,2,3};
    //int arr[N] = {1,2,3,4,5,6};
    int arr[N] = {4,0,1,1};
    int w = fun(arr);
    printf("%d
", w);
return 0; }
原文地址:https://www.cnblogs.com/dongzhuangdian/p/5862010.html