algorithm
[DP] 2011
tonirr
2020. 5. 5. 02:52
public class Main {
static long dp[];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
sc.close();
int length = str.length();
dp = new long[length + 1];
dp[0] = dp[1] = 1;
if(str.charAt(0) == '0')
System.out.println(0);
else if(str.charAt(length-1) == '0' && str.charAt(length-2) != '1' && str.charAt(length-2) != '2')
System.out.println(0);
else
for(int i = 2; i <= length; i++) {
int tmp = Integer.parseInt(str.charAt(i-1)+"");
if(tmp > 0) dp[i] = dp[i-1] % 1000000;
tmp += Integer.parseInt(str.charAt(i-2)+"")*10;
if(10 <= tmp && tmp <= 26)
dp[i] = (dp[i] + dp[i-2]) % 1000000;
}
System.out.println(dp[length]);
}
}