Cod sursa(job #2406470)

Utilizator bruhbruhbruhbruh bruh bruhbruhbruh Data 15 aprilie 2019 19:26:52
Problema Subsir crescator maximal Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.04 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

int n;
int  a[100041];
int dp[100041];
int  t[100041];
int nq;

int main()
{
    fin >> n;
    for(int i = 0; i < n; i++)
        fin >> a[i];
    for(int i = 0; i < n; i++)
    {
        int mx = 0;
        t[i] = -1;
        for(int j = 0; j < i; j++)
        {
            if(a[j] < a[i])
            {
                if(mx < dp[j])
                {
                    mx = dp[j];
                    t[i] = j;
                }

            }
        }
        dp[i] = mx+1;
    }
    int mx = 0;
    int pos;
    for(int i = 0; i < n; i++)
    {
        if(dp[i] > mx)
        {
            mx = dp[i];
            pos = i;
        }
    }
    fout << mx << "\n";
    vector<int> sol;
    while(pos != -1)
    {
        sol.push_back(a[pos]);
        pos = t[pos];
    }
    for(int i = sol.size()-1; i >= 0; i--)
        fout << sol[i] << " ";
    return 0;
}