输入描述:
输入包括两行,第一行包含一个整数n(1 ≤ n ≤ 10000) 第二行包括n个整数,表示h数组中的每个值,h_i(1 ≤ h_i ≤ 1,000,000)
输出描述:
输出一个整数,表示最大的矩阵面积。
输入例子1:
6 2 1 5 6 2 3
输出例子1:
10
代码:
#include<iostream>
#include<vector>
using namespace std;
int sort(int *a, int low, int high)
{
int min = low;
for (int i = low + 1; i <= high; i++)
{
if (a[i]<a[min])
min = i;
}
return min;
}
int area(int *a, int low, int high)
{
int pivot;
int area_max;
if (low == high)
return a[low];
else if (low<high)
{
int area_1, area_2, area_3;
pivot = sort(a, low, high);
area_2 = (high - low + 1)*a[pivot];
area_1 = area(a, low, pivot - 1);
area_3 = area(a, pivot + 1, high);
area_max = (area_1>area_2) ? area_1 : area_2;
area_max = (area_3>area_max) ? area_3 : area_max;
return area_max;
}
return 0;
}
int main()
{
/*int n = 0, hi = 0, sum = 0;
vector<int>h;
vector<vector<int>>sumjm;
cin >> n;
h.push_back(n);
while (n--)
{
cin >> hi;
h.push_back(hi);
}*/
int N;
while (cin >> N)
{
int * p = new int[N];
for (int i = 0; i<N; i++)
cin >> p[i];
int max = area(p, 0, N - 1);
cout << max;
}
return 0;
}