G title: subsequence
The meaning of problems: Given a two-character string numbers s, t, is calculated as the number of the sub-sequence s after a positive integer larger than the sub-sequence of t.
Analysis: subsequence length t s is greater than a certain ratio of large t (negative beginning with 0), by combining a number of pre-treatment can be obtained, the key operator sequence length equal to t s is greater than t, there are several. Clearly use herein dp practice, with s, t from right to left in a state of the position mark dp, dp [i] [j] indicates the state: the maximum number of strings before i and s j front string of t . For each state, it must contain a s position on the state, then according to a new first entry is the same as the first item plus t more than the number, if greater than , to use selected principles are selected on plus a number of combinations of the selected head, if the same can also add value dp are recorded on an ever selected.
#include<cstdio> using namespace std; typedef long long ll; const int maxn=3007; const int mod=998244353; ll C[maxn][maxn]; ll dp[maxn][maxn]; char s[maxn],t[maxn]; void init_C(){ C[0][0]=1; for(int i=1; i<maxn; i++){ C[i][0]=1; for(int j=1; j<=maxn; j++){ C[i][j] = ( C[i-1][j]+C[i-1][j-1] )%mod; } } } int main(){ init_C(); int T; scanf("%d",&T); int n,m; while(T--){ scanf("%d%d",&n,&m); scanf("%s%s",s,t); for(int i=0; i<=n; i++){ for(int j=0; j<=m; j++){ dp[i][j]=0; } } ll ans=0; //线性递推的二维dp for(int i=m-1; i>=0; i--){ for(int j=n-1; j>=0; j--){ ( dp[j][i] += dp[j+1][i] )%=mod; //Security at the end of the IF (S [J] == T [I]) (DP [J] [I] + = DP [J + . 1 ] [I + . 1 ])% = MOD; // can add up opportunities for the else IF ( S [J]> T [I]) (DP [J] [I] + = C [N- . 1 -j] [M- . 1 -i]); // selected thought, it is selected which one C dp recursive calculation rather than direct, meaning brutal growth } } ANS + dp = [ 0 ] [ 0 ]; // the printf ( "% LLD ANS = \ n-", ANS); for ( int I = N- . 1 ; I > = 0 ; i-- ) { IF ! (S [I] = ' 0 ') { For ( int J = Ni; J> = m + . 1 ; J, ) { // the printf ( "% D% D \ n-", I, J); (ANS + C = [N- . 1 -i] [ J- . 1 ]) MOD =%; // selected principles supra } } } the printf ( " % LLD \ n- " , ANS); } }