1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <stdio.h>
#include <stdlib.h>
long calcSum(long s) {
if(s==0) return 1;
if(s>18) return 0;
if(s < 10)
{
return s+1;
} else
{
return 19 - s;
}
}
long long findPath(long long p) {
if(p<=9)
{
return calcSum(p);
}
long long sum =0;
long w = p%100;
if (w >=10 && w<19) {
sum = calcSum(w)*findPath((p-w)/100);
}
w = p%10;
sum+= calcSum(w)*findPath((p-w)/10);
return sum;
}
int main() {
long long n;
scanf("%lld",&n);
long long w = findPath(n);
printf("%lld",w);
return 0;
}
|