Pagini recente » Cod sursa (job #1524957) | Cod sursa (job #1577750) | Cod sursa (job #578105) | Cod sursa (job #1742257) | Cod sursa (job #3331279)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("subsir.in");
ofstream fout("subsir.out");
const int NMAX = 500;
const int MOD = 666013;
int n, m, answer;
string a, b;
int dp[NMAX + 1][NMAX + 1][NMAX + 1];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
fin >> a >> b;
n = a.size();
m = b.size();
a = "%" + a;
b = "%" + b;
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= m; j++) {
dp[0][i][j] = 1;
}
}
for(int l = 1; l <= min(n, m); l++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i] == b[j]) {
dp[l][i][j] = dp[l - 1][i - 1][j - 1];
}
// if(l == 2 && i == n && j == m - 1) {
//// fout << dp[l][i - 1][j] << ' ' << dp[l][i][j - 1] << ' ' << dp[l][i - 1][j - 1] << '\n';
// }
dp[l][i][j] = (dp[l][i][j] + dp[l][i - 1][j] + dp[l][i][j - 1] - dp[l][i - 1][j - 1]) % MOD;
}
}
}
// fout << dp[1][3][2] << '\n';
// fout << dp[0][2][1] << '\n';
for(int l = 1; l <= min(n, m); l++) {
if(dp[l][n][m]) {
answer = dp[l][n][m];
}
}
fout << answer << '\n';
return 0;
}