Pagini recente » Cod sursa (job #2665503) | Cod sursa (job #2489627) | Cod sursa (job #1531963) | Cod sursa (job #3259049) | Cod sursa (job #1146544)
#include<iostream>
#include<fstream>
using namespace std;
int n, c=0, p, v[100002], b[100002], pre[100002];
ofstream g("scmax.out");
void sol(int x){
if(!c--)return;
sol(pre[x]);
g<<v[x]<<" ";
}
int main(){
ifstream f("scmax.in");
f>>n;
for(int i=1;i<=n;i++)
f>>v[i];
/*for(int i=n;i>=1;i--)
{
b[i]=1;
for(int j=i;j<=n;j++)
if(b[i]<b[j]+1 && v[i]<v[j])
{
b[i]=b[j]+1;
pre[i]=j;
c=max(c, b[i]);
p=(c==b[i])?i:p;
}
}*/
for(int i=1;i<=n;i++)
{
b[i]=1;
for(int j=1;j<i;j++)
if(b[i]<b[j]+1 && v[i]>v[j])
{
b[i]=b[j]+1;
pre[i]=j;
if(c<b[i]){
c=b[i];
p=i;
}
}
}
g<<c<<"\n";
sol(p);
return 0;
g<<c<<"\n";
while(c--)
{
g<<v[p]<<" ";
p=pre[p];
}
return 0;
}