Pagini recente » Cod sursa (job #1928999) | Cod sursa (job #2211410) | Cod sursa (job #2374572) | Cod sursa (job #2107496) | Cod sursa (job #1206823)
#include <fstream>
using namespace std;
ifstream fin ("scmax.in");
ofstream fout("scmax.out");
int N, v[100000];
int DP[100000], Next[100000];
void show()
{
int Max = 0, posMax = 0;
for(int i = 0; i < N; i++)
{
if(DP[i] > Max)
{
Max = DP[i];
posMax = i;
}
}
fout << Max << "\n";
int j = posMax;
while(j)
{
fout << v[j] << " ";
j = Next[j];
}
}
void solve()
{
for(int i = N - 1; i >= 0; i--)
Next[i]=-1;
for(int i = N - 1; i >= 0; i--)
{
DP[i] = 0;
for(int j = i + 1; j < N; j++)
{
if(v[i] < v[j] && DP[i] < DP[j])
{
DP[i] = DP[j];
Next[i] = j;
}
//fout << v[i] << " compar cu " << v[j] << "\n";
}
DP[i] += 1;
//fout << "\n";
}
show();
}
void read()
{
fin >> N;
for(int i = 0; i < N; i++)
fin >> v[i];
solve();
}
int main()
{
read();
return 0;
}