tipstar0125 / atcoder

atcoder
6 stars 0 forks source link

ABC211 C - chokudai #15

Open tipstar0125 opened 1 year ago

tipstar0125 commented 1 year ago

https://atcoder.jp/contests/abc211/tasks/abc211_c https://atcoder.jp/contests/abc211/submissions/47585101

tipstar0125 commented 1 year ago
input! {
    S: Chars
}

let T = "chokudai".chars().collect_vec();
let mut dp = vec![vec![Mod::zero(); T.len() + 1]; S.len() + 1];
for i in 0..=S.len() {
    dp[i][0] = Mod::one();
}

for i in 1..=S.len() {
    let s = S[i - 1];
    for j in 1..=T.len() {
        let t = T[j - 1];
        dp[i][j] = dp[i - 1][j];
        if s == t {
            let z = dp[i - 1][j - 1];
            dp[i][j] += z;
        }
    }
}
println!("{}", dp[S.len()][T.len()].value());
tipstar0125 commented 1 year ago
tipstar0125 commented 1 year ago

類題