Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 请大家帮忙看一下， 一维存路径， 能想到的数据都测试过了， WA

Posted by bestofme at 2014-04-06 20:25:21 on Problem 2127
// LCIS

#include <stdio.h>

#define N	501
int A[N], B[N], P[N], F[N] = {0};
int n, m;

void print(int i, int c) {
if (c == 0) {
return;
} else {
print(P[i], c-1);
printf("%d ", B[i]);
}
}

int main() {
int i, j, k, ans = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &A[i]);
}
scanf("%d", &m);
for (i = 1; i <= m; i++) {
scanf("%d", &B[i]);
}

for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (A[i] == B[j]) {
if (F[j] == 0) F[j] = 1;
for (k = 1; k < j; k++) {
if (B[k] < B[j] && F[j] < F[k] + 1) {
F[j] = F[k] + 1; P[j] = k;
}
}
}
}
}
for (i = 1; i <= m; i++) {
if (ans < F[i]) {
ans = F[i];
j = i;
}
}

printf("%d\n", ans);
print(j, ans);
printf("\n");
}

Followed by:

User ID:
Title:

Content: