形如:题意:给一个字符串,求子序列“xyz...x”出现的次数
两道板子题:https://ac.nowcoder.com/acm/contest/3947/I
https://ac.nowcoder.com/acm/contest/87/B【注意:是否区分大小写】
1 #include<bits/stdc++.h> 2 3 using namespace std; 4 #define int long long 5 #define mod 20010905 6 int dp[66]; 7 signed main(){ 8 string s; 9 cin>>s; 10 11 for(int i=0;i<s.size();i++){ 12 s[i]=tolower(s[i]); 13 dp[8]=(dp[8]+(s[i]=='u')*dp[7])%mod; 14 dp[7]=(dp[7]+(s[i]=='o')*dp[6])%mod; 15 dp[6]=(dp[6]+(s[i]=='y')*dp[5])%mod; 16 dp[5]=(dp[5]+(s[i]=='e')*dp[4])%mod; 17 dp[4]=(dp[4]+(s[i]=='v')*dp[3])%mod; 18 dp[3]=(dp[3]+(s[i]=='o')*dp[2])%mod; 19 dp[2]=(dp[2]+(s[i]=='l')*dp[1])%mod; 20 dp[1]=(dp[1]+(s[i]=='i'))%mod; 21 } 22 cout<<dp[8]; 23 return 0; 24 }
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int inf=1<<30; 4 typedef long long ll; 5 const double pi=acos(-1); 6 const int mod=2000120420010122; 7 const int maxn=2e5+7; 8 ll dp[5]; 9 int main(){ 10 string s; 11 while(cin>>s){ 12 memset(dp,0,sizeof(dp)); 13 for(int i=0;i<s.length();i++){ 14 s[i]=tolower(s[i]); 15 dp[4]=(dp[4]+(s[i]=='c')*dp[3])%mod; 16 dp[3]=(dp[3]+(s[i]=='b')*dp[2])%mod; 17 dp[2]=(dp[2]+(s[i]=='w')*dp[1])%mod; 18 dp[1]=(dp[1]+(s[i]=='c'))%mod; 19 } 20 cout<<dp[4]<<endl; 21 } 22 return 0; 23 }