题目大意:给一个建筑的序列,建筑用高度和宽度描述,找出按高度的LIS和LDS,最长XX子序列的长度按照序列中建筑的宽度和进行计算。
其实就是带权的最长XX子序列问题,原来是按个数计算,每个数权都是1,现在有不同的权重。
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAXN 100000 int h[MAXN], w[MAXN], lis[MAXN], lds[MAXN]; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int T;
scanf("%d", &T);
for (int kase = ; kase <= T; kase++)
{
int n;
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", &h[i]);
for (int i = ; i < n; i++)
scanf("%d", &w[i]);
for (int i = ; i < n; i++)
{
lis[i] = lds[i] = w[i];
for (int j = ; j < i; j++)
{
if (h[i] > h[j]) lis[i] = max(lis[i], lis[j]+w[i]);
if (h[i] < h[j]) lds[i] = max(lds[i], lds[j]+w[i]);
}
}
int a = , b = ;
for (int i = ; i < n; i++)
{
a = max(a, lis[i]);
b = max(b, lds[i]);
}
if (a >= b) printf("Case %d. Increasing (%d). Decreasing (%d).\n", kase, a, b);
else printf("Case %d. Decreasing (%d). Increasing (%d).\n", kase, b, a);
}
return ;
}