Cod sursa(job #1488693)
| Utilizator | Data | 19 septembrie 2015 15:53:51 | |
|---|---|---|---|
| Problema | Subsir crescator maximal | Scor | 70 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.84 kb |
#include<fstream>
#define DM 100006
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int N,Max,BS;
int X[DM],Best[DM],Succ[DM];
int main()
{
int i,j;
fin>>N;
for(i=1; i<=N; ++i)
fin>>X[i];
for(i=N; i>=1; --i)
{
for(j=i+1;j<=N;++j)
if(X[i]<X[j])
{
if(Best[i]<Best[j])
{
Best[i]=Best[j];
Succ[i]=j;
}
}
Best[i]++;
}
for(i=1;i<=N;++i)
if(Best[i]>Max)
{
Max=Best[i];
BS=i;
}
fout<<Max<<"\n";
i=BS;
while(i)
{
fout<<X[i]<<" ";
i=Succ[i];
}
fout<<"\n";
fin.close();
fout.close();
return 0;
}
