最大直方图面积
栈中存高度单调递增的下标
int LargestRectangleArea(int a[],int n)
{
a[n++]=0;
stack<int> s;
int LargestArea = 0;
int temp, i = 0;
while (i < n)
{
if (s.empty() || (a[i] > a[s.top()]))
{
s.push(i);
i++;
}
else
{
temp = s.top();
s.pop();
LargestArea = max(LargestArea, a[temp] *(s.empty() ? i : i - s.top() - 1) );
}
}
return LargestArea;
}

浙公网安备 33010602011771号