Pagini recente » Cod sursa (job #49012) | Cod sursa (job #1476994) | Cod sursa (job #234359) | Borderou de evaluare (job #2670086) | Cod sursa (job #1375057)
#include <fstream>
#define NMAX 100005
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int N,Value[NMAX],DP[NMAX],Next[NMAX];
int Father;
void Read(){
f>>N;
for (int i = 1; i <= N; ++i) {
f>>Value[i];
}
}
void Solve(){
for (int i = N; i >= 1; i--) {
DP[i] = 0;
for (int j = i+1; j <= N; j++) {
if(Value[i] < Value[j] && DP[i] < DP[j]){
DP[i] = DP[j];
Next[i] = j;
}
}
DP[i]++;
}
}
void Write(){
int max = 0;
for (int i = 0; i <= N; ++i) {
if (max < DP[i]) {
max = DP[i];
Father = i;
}
}
g<<max<<"\n";
while (Father) {
g<<Value[Father]<<" ";
Father = Next[Father];
}
}
int main() {
Read();
Solve();
Write();
return 0;
}