// Longest strictly increasing subsequence // Based on D. Gries, The Science of Programming, p. 262 // which is based on M. Fredman, Discrete Mathematics 11 (1975), // 29-35. #include #define MAXN (1000) main() { int n; int b[MAXN]; // Input sequence int m[MAXN+1]; // m[i] is the smallest value for an SIS with i numbers int seq[MAXN+1]; // Result sequence int sub[MAXN+1]; // Predecessor to b[i] in some SIS int mLink[MAXN+1]; // The value j for the b[j] last used to set m[i] int i,j,k,mid,low,high; scanf("%d",&n); for (i=0;im[k]) { k++; m[k]=b[i]; sub[i]=mLink[k-1]; mLink[k]=i; } else if (b[i]b[i] || m[high]<=b[i]) printf("error\n"); if (m[high-1]==b[i]) { printf("b[%d]==%d skipped\n",i,b[i]); continue; } m[high]=b[i]; sub[i]=mLink[high-1]; mLink[high]=i; } printf(" i b m mLink sub\n"); for (i=0;ik) printf(" "); else printf("%5d %5d ",m[i],mLink[i]); printf("%3d\n",sub[i]); } printf("k is %d\n",k); // Get result sequence i=mLink[k]; for (j=k-1;j>=0;j--) { seq[j]=b[i]; i=sub[i]; } for (i=0;i