CF -- Phone Number

Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u

[]   [Go Back]   [Status]  

Description

Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy.

The phone number is divined like that. First one needs to write down one's own phone numbers. For example, let's suppose that Masha's phone number is12345. After that one should write her favorite digit from 0 to 9 under the first digit of her number. That will be the first digit of the needed number. For example, Masha's favorite digit is 9. The second digit is determined as a half sum of the second digit of Masha's number and the already written down first digit from her beloved one's number. In this case the arithmetic average equals to (2 + 9) / 2 = 5.5. Masha can round the number up or down, depending on her wishes. For example, she chooses the digit 5. Having written down the resulting digit under the second digit of her number, Masha moves to finding the third digit in the same way, i.e. finding the half sum the the third digit of her number and the second digit of the new number. The result is (5 + 3) / 2 = 4. In this case the answer is unique. Thus, every i-th digit is determined as an arithmetic average of the i-th digit of Masha's number and the i - 1-th digit of her true love's number. If needed, the digit can be rounded up or down. For example, Masha can get:

12345
95444
Unfortunately, when Masha tried dialing the number, she got disappointed: as it turned out, the number was unavailable or outside the coverage area. But Masha won't give up. Perhaps, she rounded to a wrong digit or chose the first digit badly. That's why she keeps finding more and more new numbers and calling them. Count the number of numbers Masha calls. Masha calls all the possible numbers that can be found by the described means of arithmancy, except for, perhaps, her own one.

 

Input

The first line contains nonempty sequence consisting of digits from 0 to 9 — Masha's phone number. The sequence length does not exceed 50.

Output

Output the single number — the number of phone numbers Masha will dial.

Sample Input

Input
12345
Output
48
Input
09
Output
15
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std ;

long long dp[52][10] ;
int map[54];
char s[52] ;

int main()
{
    int n , mun  , i , j;
    //freopen("in.txt","r",stdin) ;
    //freopen("oo.txt","w",stdout) ;
    while( scanf("%s",s) != EOF )
    {
        n = strlen(s) ;
        map[0] = s[0]-'0' ;
        for( i = 1 ; i < n ;i++ )
        {
            map[i] = s[i]-'0' ;
        }
        memset(dp,0,sizeof(dp)) ;
        for( i = 0 ; i <= 9 ;i++ ){
            dp[0][i] = 1 ;
        }
        for( j = 1 ; j < n ;j++ )
        {
            for( i = 0 ; i <= 9 ;i++ )
          {
            if(i*2-1-map[j]>=0 &&i*2-1-map[j] <= 9)dp[j][i] += dp[j-1][i*2-1-map[j]] ;
            if(i*2-map[j]>=0 &&i*2-map[j]<=9 )dp[j][i] += dp[j-1][i*2-map[j]] ;
            if(i*2+1-map[j]<=9 &&i*2+1-map[j] >=0 )dp[j][i] += dp[j-1][i*2+1-map[j]] ;
          }
        }
        long long  ans = 0 ;
        for( i = 0 ; i <= 9 ;i++ )
           ans += dp[n-1][i] ;

    int *a = map ;
    bool flag = 1 ;
    int pre = a[0] ;
    for(int i=1; i< n; i++){
        int t = pre + a[i] ;
        if(t % 2 == 1){
            if(t / 2 != a[i] && t / 2 + 1 != a[i])  flag = 0 ;
        }else{
            if(t / 2 != a[i])   flag = 0 ;
        }
        pre = a[i] ;
    }
    if(flag){ ans-- ; }
        cout << ans << endl ;
    }
    return 0 ;
}
View Code

 

转载于:https://www.cnblogs.com/20120125llcai/p/3292653.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值