Cod sursa(job #895303)
| Utilizator | Data | 27 februarie 2013 10:51:29 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.79 kb |
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int l[100],x[100],n,ant[100],a,lmax,aux,p;
void solutie(int p)
{ if(p>=0)
{
solutie(ant[p]);
g<<x[p]<<" ";
}
}
int main()
{ int i,j;
f>>n;
for(i=0;i<n;i++)
f>>x[i];
for(i=0;i<n;i++)
{
lmax=0;a=-1;
for(j=0;j<i;j++)
if(x[i]>x[j])
if(l[j]>lmax)
{
lmax=l[j]; a=j;
}
ant[i]=a; l[i]=lmax+1;
lmax=0; p=0;
}
for(i=0;i<n;i++)
{ if(l[i]>lmax)
{
p=i;
lmax=l[i];
}
}
solutie(p);
return 0;
}
