Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int v[10],n,lmax[10],succ[10];
- void citire()
- {
- FILE *fin;
- fin=fopen("date.in","r");
- fscanf(fin,"%d",&n);
- int i;
- for(i=0;i<n;i++)
- fscanf(fin,"%d",&v[i]);
- fclose(fin);
- lmax[n-1]=1;
- succ[n-1]=-1;
- }
- void subsir()
- {
- int i,j,max=0;
- for(i=n-2;i>=0;i--)
- {
- lmax[i]=1;
- succ[i]=-1;
- for(j=i+1;j<n;j++)
- {
- if(v[j]>=v[i] && 1+lmax[j]>lmax[i])
- {
- lmax[i]=1+lmax[j];
- succ[i]=j;
- }
- }
- }
- for(i=0;i<n;i++)
- if(lmax[i]>lmax[max])
- max=i;
- printf("Lungimea maxima e %d.\n",lmax[max]);
- for(i=max; i!=-1; i=succ[i])
- printf("%d ",v[i]);
- }
- int main()
- {
- citire();
- subsir();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement