Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void beolvas(int a[],int &n)
- {
- cout<<"n=";cin>>n;
- for(int i=1;i<=n;i++)
- cin>>a[i];
- }
- void visszakeres(int ind, int index[], int a[])
- {
- if(index[ind]==0) cout<<a[ind]<<" ";
- else
- {
- visszakeres(index[ind], index, a);
- cout<<a[ind]<<" ";
- }
- }
- int main()
- {
- int a[30],hossz[30],index[30],n;
- beolvas(a,n);
- hossz[1]=1; index[1]=0;
- for(int i=2;i<=n;i++)
- {
- int max=0,ind=0;
- for(int j=1;j<=i-1;j++)
- if(a[j]<a[i] && hossz[j]>max)
- {
- max=hossz[j];
- ind=j;
- }
- hossz[i]=max+1;
- index[i]=ind;
- }
- /** for(int i=1;i<=n;i++)
- cout<<hossz[i]<<" ";
- cout<<endl;
- for(int i=1;i<=n;i++)
- cout<<index[i]<<" ";
- cout<<endl;
- */
- int maxim=0,ind;
- for(int i=1;i<=n;i++)
- if(a[i]>maxim)
- {
- maxim=hossz[i];
- ind=i;
- }
- cout<<"A leghosszabb novekvo reszsorozat hossza "<<maxim<<endl;
- visszakeres(ind, index, a);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement