Cod sursa(job #1654258)

Utilizator andrew_assassin789Andrei Manea andrew_assassin789 Data 16 martie 2016 22:01:28
Problema Cel mai lung subsir comun Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <fstream>
#include <algorithm>
#include <vector>
#define w 257
#define ws 1025
using namespace std;
char mt[w][w];
vector <char>sol;
char a[ws],b[ws];
char n,m;
void pd()
{
    int i,j;
    for (i=1;i<=m-'0';i++)//b
    {
        for (j=1;j<=n-'0';j++)//a
        {
            if (a[j]==b[i])
            {
                mt[i][j]=mt[i-1][j-1]+1;
                sol.push_back(b[i]);
            }
            else mt[i][j]=max(mt[i-1][j],mt[i][j-1]);
        }
    }
}
int main()
{
    ifstream f("cmlsc.in");
    ofstream g("cmlsc.out");
    char i;
    f>>n>>m;
    for (i=1;i<=n-'0';i++)
        f>>a[i];
    for (i=1;i<=m-'0';i++)
        f>>b[i];
    pd();
    g<<sol.size()<<'\n';
    for (i=0;i<sol.size();i++)
    {
        g<<sol[i]<<' ';
    }
    g<<'\n';
    f.close();
    g.close();
    return 0;
}