알고리즘

[알고리즘] 백준 2011 - 암호코드 (C++)

blueberrysoda 2024. 8. 30. 19:04

[문제 링크] : https://www.acmicpc.net/problem/2011

#include <iostream>
using namespace std;

int DP[5001];

int main(){
    string S;
    cin >> S;

    DP[0] = DP[1] = 1;

    for(int i=2; i<=S.size(); i++){
        if(S[i-1] != '0'){
            DP[i] = DP[i-1] % 1000000;
        }
        int res = (S[i-2] - '0') * 10 + (S[i-1] - '0');
        if(res >= 10 && res <= 26){
            DP[i] = (DP[i] + DP[i-2]) % 1000000;
        }
    }
    
    if(S[0] == '0') cout << 0 << "\n";
    else cout << DP[S.size()] << "\n";

    return 0;
}