Problem Description
Vasily Tadokorov is a stringologist. He thinks a string is fragrant if it can be divided into two parts — nunhehheh as the prefix and a number of (excluding 0) a as the suffix. For example, nunhehhehaaaaaa is fragrant, but nunhehheh and nunhehhehoooaaa are not fragrant.
Today Vasily Tadokorov has some strings consisting of lowercase English letters. For each string, he wants to know how many subsequences of this string are fragrant. A string a is a subsequence of a string b if a can be obtained from b by deletion of several (including 0) characters.
题意描述:问这个字符串有多少种删除方式;每删除一个字母就要加上他的a字母后缀和的(2^n-1)*前缀dp的特定字符串个数。
dp方程为:dp[i]j]=dp[i][j-1]+dp[i-1][j-1];
后缀和为:2^n-1;可以先从一跑到1e5存到数组中,然后用时直接调用下表,也可快速幂:
#include<iostream>
#include<cstring>
using namespace std;
int mod=998244353;
int a[100002];
int num[100002];
int dp[9][100002];
int main()
{
int t;
cin>>t;
a[0]=1;
for(int i=1; i<=1e5+1; i++)
a[i]=(a[i-1]*2)%mod;
while(t--)
{
string s