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了。这个破Judge也不告诉你是什么Test Case上出错了,真郁闷!#include <algorithm> using namespace std; #include <stdio.h> int lcis(int a[], int m, int b[], int n, int c[]) { int lcis[512]={0}; int pi[512]={-1}; for(int i=0; i<m; i++) { int k=-1; for(int j=0; j<n; j++) { if(b[j]<a[i]) { if(k==-1 || lcis[j]>lcis[k]) k=j; } else if(a[i]==b[j]) { int t= (k>=0) ? 1+lcis[k] : 1; if(t>lcis[j]) { lcis[j]=t; pi[j]=k; } } } } int idx=(int)(max_element(lcis, lcis+n)-lcis); int l=lcis[idx]; for(int p=idx, k=l-1; k>=0 && p>=0; p=pi[p], k--) c[k]=b[p]; return l; } int main() { int a[512]={0}; int b[512]={0}; int c[512]={0}; int m=0, n=0, l=0; scanf("%d", &m); for(int i=0; i<m; i++) scanf("%d", a+i); scanf("%d", &n); for(int j=0; j<n; j++) scanf("%d", b+j); l=lcis(a, m, b, n, c); printf("%d\n", l); for(int k=0; k<l; k++) printf("%d ", c[k]); printf("\n"); return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator