其他分享
首页 > 其他分享> > 3.28 每日一题题解

3.28 每日一题题解

作者:互联网

tokitsukaze and Segmentation

涉及知识点:

solution:

std:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 100005;
const ll mod = 998244353;
char s[maxn];
ll dp[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s+1);
    ll ans = 1;
    int cnt = 0;
    dp[0] = 1;
    for(int i=1;i<=n;i++){
        cnt = (cnt + (s[i]-'0'))%3;
        if(cnt)continue ;
        dp[i] = ans ;
        if(s[i] == '0')
            ans = (ans - dp[i-1] + mod)%mod;
        ans = (ans + dp[i])%mod;
    }
    cout<<dp[n]<<endl;
    return 0;
}

标签:std,int,题解,每日,long,maxn,3.28,ll,dp
来源: https://www.cnblogs.com/QFNU-ACM/p/12586514.html