Cod sursa(job #149028)
Utilizator | Data | 5 martie 2008 11:20:10 | |
---|---|---|---|
Problema | Subsir 2 | Scor | 25 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.62 kb |
#include<fstream.h>
ifstream f ("subsir2.in");
ofstream g("subsir2.out");
long long n,i,lm,p,l[5001],a[5001];
void dinamica()
{
int i,j,max;
l[n]=1;
for(i=n-1;i>=1;i--)
{
max=0;
for(j=i+1;j<=n;j++)
if(l[j]>max&&a[i]<=a[j])
max=l[j];
l[i]=max+1;
if(lm<l[i])
lm=l[i];
}
g<<lm;
g<<"\n";
}
void drum()
{
int t;
t=0;
p=1;
do
{
while(l[p]!=lm||a[t]>a[p])
p++;
g<<a[p]<<" ";
t=p;
lm--;
}while(lm);
}
int main()
{
f>>n;
for(i=1;i<=n;i++)
f>>a[i];
dinamica();
drum();
return 0;
}