I I love you

題目:I love you

簡單DP。分析做的每一道DP.
不同的子序列 解法1

#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
const ll mod = 20010905;
ll f[10];
 

//此時的f數組所對應的相當與iloveyou = t,
//在s中找t出現的次數,
//dp[i][j]表示在s (0~i-1)中出現 t (0~j-1)的次數。
string s;

void solve(){
    int n = s.size();
    for(int i = 0;i < n;i++){
        if(s[i] == 'i' || s[i] == 'I') f[1] = (f[1]+1)%mod;
        if(s[i] == 'l' || s[i] == 'L') f[2] = (f[2]+f[1])%mod;
        if(s[i] == 'o' || s[i] == 'O') f[3] = (f[3]+f[2])%mod;
        if(s[i] == 'v' || s[i] == 'V') f[4] = (f[4]+f[3])%mod;
        if(s[i] == 'e' || s[i] == 'E') f[5] = (f[5]+f[4])%mod;
        if(s[i] == 'y' || s[i] == 'Y') f[6] = (f[6]+f[5])%mod;
        if(s[i] == 'o' || s[i] == 'O') f[7] = (f[7]+f[6])%mod;
        if(s[i] == 'u' || s[i] == 'U') f[8] = (f[8]+f[7])%mod;
    }
    cout<<f[8]%mod<<endl;
}
int main(){
    cin >> s;
    solve();
    return 0;
}
發佈了335 篇原創文章 · 獲贊 25 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章