Cod sursa(job #843441)

Utilizator Theorytheo .c Theory Data 27 decembrie 2012 22:49:33
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.36 kb
#include<fstream>
#include<vector>
#include<cstring>
using namespace std;

ifstream fin("decrease.in");
ofstream fout("decrease.out");

#define NMAX 5005
#define KMAX 1<<16

int N, v[NMAX], Number_Solutions[NMAX], best[NMAX];
bool viz[KMAX];
void read(){
    fin >>N;
    for(int i = 1; i <= N; i++)
        fin >> v[i], Number_Solutions[i] = 1;

}

void dinamic(){

    Number_Solutions[1] = 1 ; best[1] = 1;
    int max_best = 0;
    for(int i = 2; i <= N; i++){
        memset(viz, 0 , sizeof(viz));
        for(int j = i - 1; j > 0 ; --j){



            if(v[i] < v[j] && viz[v[j]] == false){
                if(best[i] == best[j] + 1)
                    Number_Solutions[i] += Number_Solutions[j];

                if(best[i] < best[j] + 1){
                    Number_Solutions[i] = Number_Solutions[j];
                    best[i] = best[j] + 1;
                }
                viz[v[j]] = true;
               }
        }
            if(best[max_best] <= best[i]) max_best = i;

    }
    int S_pos = 0;
    fout << best[max_best]<<" ";
    for(int i = 1; i <= N ; ++i){
        //fout << Number_Solutions[i]  <<"  "<<best[i] <<'\n'; ;
        if(best[i] == best[max_best] && (v[max_best] != v[i] || (!S_pos) ) )
            S_pos += Number_Solutions[i];
    }
    fout << S_pos;

}
int main(){
    read();
    dinamic();
}