Pagini recente » Cod sursa (job #2314750) | Cod sursa (job #221182) | Cod sursa (job #3146951) | Cod sursa (job #2623487) | Cod sursa (job #2636168)
#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
#define MOD (666013)
int t, n, m;
string a, b;
int dp[510][510], pos[510][510];
char l[510][510];
ifstream fin("subsir.in"); ofstream fout("subsir.out");
#define cin fin
#define cout fout
int32_t main(){
INIT
cin>>a>>b;
n=a.length(); m=b.length();
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(a[i-1]==b[j-1]){
dp[i][j]=dp[i-1][j-1]+1; l[i][j]=a[i-1]; pos[i][j]+=pos[i-1][j-1];
if(pos[i][j]==0){pos[i][j]++;}
}
if(dp[i-1][j]>=max(max(dp[i-1][j-1], dp[i][j-1]), dp[i][j] ) ){
dp[i][j]=dp[i-1][j]; if(l[i][j]!=l[i-1][j]){l[i][j]=l[i-1][j]; pos[i][j]+=pos[i-1][j]; }
}
if(dp[i-1][j-1]>=max(max(dp[i-1][j], dp[i][j-1]), dp[i][j] ) ){
dp[i][j]=dp[i-1][j-1]; if(l[i][j]!=l[i-1][j-1]){l[i][j]=l[i-1][j-1]; pos[i][j]+=pos[i-1][j-1]; }
}
if(dp[i][j-1]>=max(max(dp[i-1][j-1], dp[i-1][j]), dp[i][j] ) ){
dp[i][j]=dp[i][j-1]; if(l[i][j]!=l[i][j-1]){l[i][j]=l[i][j-1]; pos[i][j]+=pos[i][j-1]; }
}
pos[i][j]%=MOD;
}
}
cout<<pos[n][m];
return 0;
}