您的位置:首页 > 产品设计 > UI/UE

【HDOJ】1423 Greatest Common Increasing Subsequence

2015-01-16 12:30 363 查看
LCIS

/* 1423 */
#include <cstdio>
#include <cstring>
#include <cstdlib>

#define MAXN 505

int a[MAXN];
int b[MAXN];
int c[MAXN];
int n, m;
int ans;

int max(int a, int b) {
return a>b ? a:b;
}

void solve() {
int i, j, k;

memset(c, 0, sizeof(c));
for (i=0; i<n; ++i) {
k = 0;
for (j=0; j<m; ++j) {
if (a[i] == b[j]) {
c[j] = max(c[j], k+1);
}
if (a[i] > b[j]) {
k = max(k, c[j]);
}
}
}
ans = -1;
for (i=0; i<m; ++i)
ans = max(ans, c[i]);
}

int main() {
int t;
int i, j, k;

#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif

scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (i=0; i<n; ++i)
scanf("%d", &a[i]);
scanf("%d", &m);
for (i=0; i<m; ++i)
scanf("%d", &b[i]);
solve();
printf("%d\n", ans);
if (t)
printf("\n");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: