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 |
1243 nouse to delete#include <stdio.h> int a[1000]; int b[1000]; int f[1001][1001]; void sort(int *b, int sum); void process(int *a, int *b, int sum); main() { int i,j; int sum; while (scanf("%d", &sum)!=EOF) { for(i=0 ;i<sum; i++) { scanf("%d",a+i); *(b+i)=*(a+i); } for(i=0; i<sum; i++) { for(j=0; j<sum; j++) { f[i][j]=0; } } sort(b, sum); process(a, b, sum); /*scanf("%d", &sum);*/ } return 0; } void process(int *a,int *b, int sum) { int i,j; for(i=0; i<sum; i++) { for(j=0; j<sum; j++) { if (a[i]==b[j]) { f[i+1][j+1] = f[i][j] + 1; } else { f[i+1][j+1] = f[i][j+1]>f[i+1][j] ? f[i][j+1] : f[i+1][j]; } } } printf("%d\n",f[sum][sum]); } void sort(int *b, int sum) { int i,j; int tmp; for(i=0; i<sum-1; i++) { for(j=i+1; j<sum; j++) { if (*(b+i)>*(b+j)) { tmp=*(b+i); *(b+i)=*(b+j); *(b+j)=tmp; } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator