Pagini recente » Cod sursa (job #2923971) | Cod sursa (job #2176239) | Cod sursa (job #1206039) | Cod sursa (job #1229291) | Cod sursa (job #655744)
Cod sursa(job #655744)
#include<fstream>
#include<iostream>
#define lmax 100001
using namespace std;
ifstream f("scmax.in",fstream::in);
ofstream g("scmax.out",fstream::out);
unsigned int a[lmax];
unsigned int b[lmax],p[lmax],n,pmax,maxim=0;
unsigned int x;
void read()
{
unsigned int i;
f>>n;
for(i=1;i<=n;i++)
{
f>>a[i];
b[i]=1;
}
}
void phd()
{
unsigned int i,j;
for(i=2;i<=n;i++)
for(j=1;j<i;j++)
if(a[i]>a[j] && b[j]>=b[i])
{
b[i]=b[j]+1;p[i]=j;
if(b[i]>maxim)
{
maxim=b[i];
pmax=i;
}
}
}
void show(short int i)
{
if(p[i]!=0)
show(p[i]);
g<<a[i]<<" ";
}
int main()
{ read();
phd();
g<<maxim<<"\n";
show(pmax);
f.close();
g.close();
return 0;
}