北郵賽2題D

來源:互聯網
上載者:User
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 1009long 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;    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.