Cod sursa(job #520666)

Utilizator tlapusanlapusan tudor tlapusan Data 9 ianuarie 2011 22:18:57
Problema Subsir crescator maximal Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.72 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream in("scmax.in");
ofstream out("scmax.out");

int n;
int a[100000];
int best[100000];
int fiu[100000];

void citeste(){
     in>>n;     
     for(int i = 0; i < n; i++){
             in>>a[i];
     }     
     
//     for(int i = 0; i < n; i++){
//             out<<a[i]<< " " ;
//     }
}

void solve(){
     best[0] = 1;
     fiu[0] = -1;
     for(int i = 1; i < n; i++){
             best[i] = 1;
             fiu[i] = -1;  
             for(int j = i - 1; j >= 0; j--){
                   if(a[i] > a[j] && best[i] < best[j] + 1){
                           best[i] = best[j] + 1;
                           fiu[i] = j;
                   }
             }        
     }
     
//     for(int i = 0; i < n; i++){
//             out<<best[i]<< " ";
//     }
}

int getMaxBest(int limit){
    int max = best[0];
    for(int i = 1; i <= limit; i++){
            if(best[i] > max){
                       max = best[i];
            }                
    }
    return max;                                     
}

void showSecvMax(int i){
     if(fiu[i] == -1){
               out<<a[i]<< " ";
               return;
     }
     showSecvMax(fiu[i]);
     out<<a[i]<< " ";
     
}
      
void showResult(){
     int pozMax = 1;
     int max = best[1];
     
     for(int i = 1; i < n; i++){
             if(best[i] > max){
                        max = best[i];
                        pozMax = i;
             }
     } 
  
     out<<max<<"\n";
     showSecvMax(pozMax);
}

                                      
int main(){    
    citeste();
    solve();
    showResult();
    
    
    
    return 0;    
}