Cod sursa(job #804397)

Utilizator raulstoinStoin Raul raulstoin Data 29 octombrie 2012 18:58:23
Problema Cel mai lung subsir comun Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <fstream>
using namespace std;
ifstream f("cmlsc.in");
ofstream g("cmlsc.out");
int n,m,best[1030][1030],a[1030][1030];
int main()
{
    f>>m>>n;
    int i,j;
    for(i=1;i<=m;i++)
        f>>a[0][i];
    for(i=1;i<=n;i++)
        f>>a[1][i];
    for(i=1;i<=m;i++)
        for(j=1;j<=n;j++)
        {
            best[i][j]=max(best[i][j-1],best[i-1][j]);
            if(a[0][i]==a[1][j])
                best[i][j]=best[i-1][j-1]+1;
        }
	g<<best[m][n]<<'\n';
    return 0;
}