北邮赛2题D

D  Password
Accept:25     Submit:68
Time Limit:1000MS     Memory Limit:65536KB

Description

ykwd's password is a number sequence. Every number in this sequence is no less than 0 and no larger than 255, and without leading zeros. ykwd wrote his password down ,but he didn't add spaces between numbers. For example, if his password is 1 34 8 205,he will write down 1348205 . Now, he has forgot his password, he only has the string he has written down, he wants to know how many different possible passwords he can have?

 

Input

The first line has one interger t, denoting the number of cases.
Nest t lines, each line includes a string ykwd wrote down.
You can suppose that each string is no longer than 1000.


Output

For each case you should output one line. Because the answer may be very large, you need only ouput the answer mod 1234567.


Sample Input

2
1234
1024


Sample Output

7
5

submit     Discuss
/*

简单的动态规划。。 

*/ 
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define manx 1009

long long dp[manx];

int main(){
    int t;
    cin>>t;
    while(t--){
        memset(dp,0,sizeof(dp));
        string s;
        cin>>s;
        if(s.size()>=1)  dp[0]=1;
        if(s.size()>=2){
            int sum = s[1]-'0';
            sum += (s[0]-'0')*10;
            if(sum>=10) dp[1]=2; 
            else dp[1]=1;
        }    
        
        if(s.size()>=3){
            int sum = s[2]-'0';
            sum += (s[1]-'0')*10;
            dp[2]+=dp[1];
            if(sum>=10) dp[2]+=1;
            sum += (s[0]-'0')*100;
            if(sum >= 100 && sum<=255) dp[2]+=1;
        }
        
        for(int i=3;i<s.size();i++){
            int sum = s[i]-'0';
            dp[i]+=dp[i-1];  dp[i]%=1234567;
            
            sum = sum + (s[i-1]-'0')*10;
            if(sum >= 10) dp[i]+=dp[i-2];  dp[i]%=1234567;
            
            sum = sum + (s[i-2]-'0')*100;
            if(sum >= 100 && sum<=255) dp[i]+=dp[i-3];  dp[i]%=1234567;
        }        
        cout<<dp[s.size()-1]<<endl;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值