题意很清楚, d p d p [ i ] [ j ] i j i 直接dp即可,dp[i][j]表示到第i个字符的状态为j的方案数,这里状态指的是子序列最大下标到第i dpdp[i][j]iji个字符 3 . 的子序列数字和取模3的值,分情况转移一下即可. 3.

#include<bits/stdc++.h>

#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;

LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
const int N = 2e5 +11;
int n;
const LL mod=1e9+7;
LL dp[55][4];
char a[55];
int main(){
    ios::sync_with_stdio(false);
    cin>>a+1;
    int len=strlen(a+1);
    for(int i=1;i<=len;i++){
        dp[i][(a[i]-'0')%3]=1;
        for(int j=1;j<i;j++){
            if((a[i]-'0')%3==0){
                dp[i][1]+=dp[j][1];
                dp[i][2]+=dp[j][2];
                dp[i][0]+=dp[j][0];
                for(int k=0;k<=2;k++)dp[i][k]%=mod;
            }else if((a[i]-'0')%3==1){
                dp[i][0]+=dp[j][2];
                dp[i][1]+=dp[j][0];
                dp[i][2]+=dp[j][1];
                for(int k=0;k<=2;k++)dp[i][k]%=mod;
            }else{
                dp[i][0]+=dp[j][1];
                dp[i][1]+=dp[j][2];
                dp[i][2]+=dp[j][0];
                for(int k=0;k<=2;k++)dp[i][k]%=mod;
            }
         }
    }
    LL ans=0;
    for(int i=1;i<=len;i++)ans=(ans+dp[i][0])%mod;
    cout<<ans<<endl;
    return 0;
}