Pagini recente » Cod sursa (job #756456) | Cod sursa (job #1092000) | Cod sursa (job #965295) | Cod sursa (job #1366861) | Cod sursa (job #1294405)
#include <fstream>
using namespace std;
const int maxn = 100005;
ifstream in("scmax.in");
ofstream out("scmax.out");
/*
lung = 1, 1, 2, 3, 1, 2, 4, 5, 5, 3
pref = 0, 0, 2, 3, 0, 5, 4, 7, 7, 6
lung[1]=1;
for(i=1;i<=n;i++){
lmax=0;
for(j=1;j<i;j++)
if(v[j]<v[i]){
lmax=lung[j];
pred[i]=j;
}
lung[i]=1+lmax;
}
lung subsirului cresc maximal --> max(lung[i])
1<=i<=n
void subsir (int p){
if(pred[p]!=0)
subsir(pred[p])
out<<v[p]<<" ";
}
*/
int n;
int a[maxn];
int m[maxn];
int f[maxn];
int b[maxn], lung;
void citire() {
in >> n;
for (int i = 1; i <= n; ++i)
in >> a[i];
}
void sol() {
b[1]=1;
for(int i=2;i<=n;i++)
{
lung=0;
for(int j;j<i;j++)
if( a[j] < a[i])
if(b[j]>lung){
lung=b[j];
m[i]=j;
}
b[i]=1+lung;
}
}
void g(int poz) {
if (poz == 0) return;
g(f[poz]);
out << a[poz] << " ";
}
void scrie() {
out << lung << endl;
for (int i = 1; i <= n; ++i)
if (m[i] == lung) {
g(i);
return;
}
}
int main() {
scrie();
sol();
scrie();
}