Cod sursa(job #1653941)

Utilizator andrew_assassin789Andrei Manea andrew_assassin789 Data 16 martie 2016 18:25:39
Problema Cel mai lung subsir comun Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 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=2;i<=m+1;i++)//b
        for (j=2;j<=n+1;j++)//a
        {
            if (a[j-1]==b[i-1])
            {
                mt[i][j]=mt[i-1][j-1]+1;
                sol.push_back(b[i-1]);
            }
            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;i++)
        f>>a[i];
    for (i=1;i<=m;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;
}