标签:blog io os for sp 2014 log amp line
题目:给你一排建筑的长度和高度,求最长的上横高度和下降高度。
分析: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; }
标签:blog io os for sp 2014 log amp line
原文地址:http://blog.csdn.net/mobius_strip/article/details/40264311