Cod sursa(job #998872)

Utilizator IancuDanielIancu Daniel Constantin IancuDaniel Data 18 septembrie 2013 16:20:30
Problema Cel mai lung subsir comun Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream ifs("clmsc.in"); ofstream ofs("clmsc.out");
unsigned char SI[1025],SII[1025],MX[1025][1025],clmsc[1025];
short int M,N,t;

int main() {
  ifs>>M>>N;
  for(int i=1;i<=M;i++)
    ifs>>SI[i];
  for(int i=1;i<=N;i++)
    ifs>>SII[i];
  for(int i=1;i<=M;i++)
    for(int j=1;j<=N;j++)
      if(SI[i]==SII[j]) {
        MX[i][j]=MX[i-1][j-1]+1;
        clmsc[t]=SI[i]; t++;
      }
      else
        MX[i][j]=max(MX[i-1][j],MX[i][j-1]);
  ofs<<MX[M][N]<<'\n';
  for (int i=0;i<t;i++)
    ofs<<clmsc[i]<<" ";
}