用dp来推断子序列个数

if (s[i] >= &#39;A&#39; && s[i] <= &#39;Z&#39;) s[i] += 32;统一小写,大小写不敏感。

dp[j] = dp[j] + (s[i] == a[j]) * dp[j - 1];如果匹配,对当前位置加上前一位。

#include <bits/stdc++.h>
using namespace std;
int n, Mod = 20010905, dp[10];
char a[] = "0iloveyou", s[684600];
int main() {
    cin >> s + 1;
    f[0] = 1;
    n = strlen(s + 1);
    for (int i = 1; i <= n; ++i) {
        if (s[i] >= &#39;A&#39; && s[i] <= &#39;Z&#39;) s[i] += 32;
        for (int j = 1; j <= 8; ++j) {
            dp[j] = dp[j] + (s[i] == a[j]) * dp[j - 1];
            dp[j] %= Mod;
        }
    }
    cout << f[8];
}