Pagini recente » Cod sursa (job #1664257) | Cod sursa (job #2099966) | Cod sursa (job #3274580) | Cod sursa (job #302181) | Cod sursa (job #1309639)
# 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;
}