http://poj.org/problem?id=2559
1 a[n + 1] = p = 0; 2 for (int i = 1; i <= n + 1; i++) 3 { 4 if (a[i] > s[p]) 5 { 6 s[++p] = a[i], w[p] = 1; 7 } 8 else 9 { 10 int width=0; 11 while (s[p] > a[i]) 12 { 13 width += w[p]; 14 ans = max(ans, (long long)width * s[p]); 15 p--; 16 } 17 s[++p] = a[i], w[p] = width + 1; 18 } 19 }
及时排除不可能的选项,保持决策集合的高度和秩序性