牛客 被3整除的子序列dp
题意很清楚,个字符
#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;
}