Cod sursa(job #1309639)

Utilizator cojocarugabiReality cojocarugabi Data 5 ianuarie 2015 21:47:55
Problema Subsir Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
# include <bits/stdc++.h>
using namespace std;
ifstream fi("subsir.in");
ofstream fo("subsir.out");
char s[505];
char sir[505];
int dp[505][505];
int v[505][505];
int main(void)
{
    int n,m;
    fi>>(s+1)>>(sir+1);
    n = strlen(s+1);
    m = strlen(sir+1);
    for (int i=1;i<=n;++i)
    {
        int vtot = 1,lmax = 1;
        for (int j=1;j<=m;++j)
            if (s[i] == sir[j])
            {
                if (lmax > dp[i-1][j] || (lmax == dp[i-1][j] && vtot > v[i-1][j])) dp[i][j] = lmax,v[i][j] = vtot;
                else dp[i][j] = dp[i-1][j],v[i][j] = v[i-1][j];
                if (lmax < dp[i-1][j])  lmax = dp[i-1][j],vtot = v[i-1][j];else
                if (lmax == dp[i-1][j]) vtot += v[i-1][j];
            }
    }
    return fo << v[n][m] << '\n',0;
}