zoukankan      html  css  js  c++  java
  • 老年选手的复健之路

    CF1426F Number of Subsequences

    Description

    一个字符串中包含(a,b,c,?) 这4种字符,(?)可变成(a,b,c)
    求所有可能的串中有多少个子串是(abc)

    Code

    展开
    
    
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
     
    const int N = 2e5 + 10;
    const int mod = 1e9 + 7;
     
    int n;
    ll ans, Fa[N], Fb[N], Fc[N];
    char ch[N];
     
    int main() {
        scanf("%d", &n);
        scanf("%s", ch + 1);
        ll pow_3 = 1;
        for (int i = 1; i <= n; ++i) {
            if (ch[i] == 'a') {
                Fa[i] = (Fa[i - 1] + pow_3) % mod;
                Fb[i] = Fb[i - 1];
                Fc[i] = Fc[i - 1];
            }
            if (ch[i] == 'b') {
                Fa[i] = Fa[i - 1];
                Fb[i] = (Fb[i - 1] + Fa[i - 1]) % mod;
                Fc[i] = Fc[i - 1]; 
            }
            if (ch[i] == 'c') {
                Fa[i] = Fa[i - 1];
                Fb[i] = Fb[i - 1];
                Fc[i] = (Fc[i - 1] + Fb[i - 1]) % mod;
            }
            if (ch[i] == '?') {
                Fa[i] = Fa[i - 1] * 3 % mod;
                Fb[i] = Fb[i - 1] * 3 % mod;
                Fc[i] = Fc[i - 1] * 3 % mod;
                Fa[i] = (Fa[i] + pow_3) % mod;
                Fb[i] = (Fb[i] + Fa[i - 1]) % mod;
                Fc[i] = (Fc[i] + Fb[i - 1]) % mod;
                pow_3 = pow_3 * 3 % mod;
            }
        } 
        printf("%lld
    ", Fc[n]);
    }
    

  • 相关阅读:
    shell得到两个文件的差集
    shell 单引号&双引号的使用
    kubernetes session and 容器root权限
    docker 使用网络以及容器互联
    倒计时练习
    会话控制
    XML
    AJAX实现搜索智能提示
    弹窗显示详情练习
    三级联动
  • 原文地址:https://www.cnblogs.com/cychester/p/13792433.html
Copyright © 2011-2022 走看看