Cod sursa(job #2194561)
| Utilizator | Data | 13 aprilie 2018 18:55:46 | |
|---|---|---|---|
| Problema | Subsir | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.28 kb |
#include<fstream>
#include<string.h>
#define MOD 666013
using namespace std;
ifstream fi("subsir.in");
ofstream fo("subsir.out");
int n,m,i,j,Dp[505][505],Modes[505][505];
char A[505],B[505];
int main()
{
fi>>(A+1);
fi>>(B+1);
n=strlen(A+1);
m=strlen(B+1);
Modes[1][1]=1;
for(i=1; i<=n; i++)
{
for(j=1; j<=m; j++)
{
if(A[i]==B[j])
{
Dp[i][j]=Dp[i-1][j-1]+1;
Modes[i][j]+=Modes[i-1][j-1];
}
else
{
if(Dp[i-1][j]!=Dp[i][j-1])
{
if(Dp[i-1][j]>Dp[i][j-1])
{
Dp[i][j]=Dp[i-1][j];
Modes[i][j]+=Modes[i-1][j];
}
else
{
Dp[i][j]=Dp[i][j-1];
Modes[i][j]+=Modes[i][j-1];
}
}
else
{
Dp[i][j]=Dp[i-1][j];
Modes[i][j]+=(Modes[i-1][j]+Modes[i][j-1]-Modes[i-1][j-1]+MOD)%MOD;
}
}
}
}
fo<<Modes[n][m]<<"\n";
fi.close();
fo.close();
return 0;
}
