Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请大家帮忙看一下, 一维存路径, 能想到的数据都测试过了, WA// 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:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator