标签:
称号:给你一个行长度的建设和高度,我们祈求最长的和下降的高度。
分析:dp,最大上升子。
说明:具有长度,不能直接优化队列单调。
#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; }
版权声明:本文博客原创文章,博客,未经同意,不得转载。
UVa 11790 - Murcia's Skyline
标签:
原文地址:http://www.cnblogs.com/bhlsheji/p/4718997.html