Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator