Question: give you a row of length and height of the building, and find the longest vertical height and descending height.
Analysis: DP, maximum ascending subsequence.
Note: It has a length and cannot be optimized using a monotonous queue directly.
#include <iostream>#include <cstdlib>#include <cstdio>using namespace std;int h[2000],w[2000],u[2000],l[2000];int main(){int T,n;while (~scanf("%d",&T))for (int t = 1 ; t <= T ; ++ t) {scanf("%d",&n);for (int i = 0 ; i < n ; ++ i) scanf("%d",&h[i]);for (int i = 0 ; i < n ; ++ i)scanf("%d",&w[i]);int in = 0,de = 0;for (int i = 0 ; i < n ; ++ i) {u[i] = l[i] = w[i];for (int j = 0 ; j < i ; ++ j) {if (h[j] < h[i] && u[i] < u[j]+w[i])u[i] = u[j]+w[i];if (h[j] > h[i] && l[i] < l[j]+w[i])l[i] = l[j]+w[i];}if (in < u[i]) in = u[i];if (de < l[i]) de = l[i];}if (in >= de)printf("Case %d. Increasing (%d). Decreasing (%d).\n",t,in,de);else printf("Case %d. Decreasing (%d). Increasing (%d).\n",t,de,in);}return 0;}
Ultraviolet A 11790-Murcia's skyline