Pagini recente » Cod sursa (job #3154977) | Cod sursa (job #853064) | Cod sursa (job #2714949) | Cod sursa (job #3184420) | Cod sursa (job #2638147)
#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 n, m;
string a, b;
ifstream fin("subsir.in"); ofstream fout("subsir.out");
#define cin fin
#define cout fout
int lta[510][300], ltb[510][300];
int l[510][510];
int nr[510][510];
int ans[510];
int32_t main(){
INIT
cin>>a>>b;
n=a.length(); m=b.length();
for(int i=1; i<=n; i++){
for(char c='a'; c<='z'; c++){
lta[i][c]=lta[i-1][c];
}
lta[i][a[i-1] ]=i;
}
for(int j=1; j<=m; j++){
for(char c='a'; c<='z'; c++){
ltb[j][c]=ltb[j-1][c];
}
ltb[j][b[j-1] ]=j;
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(a[i-1]==b[j-1]){
l[i][j]=l[i-1][j-1]+1;
for(char c='a'; c<='z'; c++){
int ii=lta[i-1][c], jj=ltb[j-1][c];
if(l[ii][jj]==(l[i][j]-1) ){
nr[i][j]+=nr[ii][jj];
nr[i][j]%=MOD;
}
}
nr[i][j]=max(nr[i][j], (int) 1);
ans[l[i][j] ]=nr[i][j]; ans[l[i][j] ]%=MOD;
}
if(l[i-1][j]>l[i][j]){
l[i][j]=l[i-1][j];
}
if(l[i-1][j-1]>l[i][j]){
l[i][j]=l[i-1][j-1];
}
if(l[i][j-1]>l[i][j]){
l[i][j]=l[i][j-1];
}
// cout<<nr[i][j]<<" ";
}
//cout<<"\n";
}
/*cout<<"\n";
for(int i=1; i<=3; i++){
for(char c='a'; c<='z'; c++){
if(crd[i][c].ft>0){
cout<<c<<" "<<crd[i][c].ft<<" "<<crd[i][c].sc<<"\n";}
}
cout<<"\n";
}*/
cout<<ans[l[n][m] ];
return 0;
}