北邮赛2题D
来源:互联网 发布:淘宝账户换虾米音乐vip 编辑:程序博客网 时间:2024/06/06 00:10
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
/*简单的动态规划。。 */ #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; }}
- 北邮赛2题D
- 省赛2D题
- (@"^-?\d+(\.\d{2})?$");解释
- Codeforces 615D Multipliers (Round #338 (Div. 2) D题)
- Codeforces 617D Polyline (Round #340 (Div. 2) D题)
- D题
- 2d
- 输出printf 时 %2d,%d,%02d,%.2d
- 2d , 3d engine
- Quartz 2D 绘图d
- 2D转3D
- 1D 2D 混合
- animal 2D 3D
- Codeforces 182 Div.2 D题
- Codeforces Round #261 (Div. 2) D题
- Codeforces Round #277 (Div. 2)D题
- codeforces#291(div.2)D题
- Codeforces Educational Round 2 D题
- Kinect sdk 1.7 Interaction API 学习和程序框架
- uva 12124 组装电脑
- 【黑马程序员】 基础回顾(一)第十四天
- I SQRT
- <%@include%>、<jsp:include>、<jsp:forward>、sendredirect
- 北邮赛2题D
- framework资源修改
- 配置busybox
- 内存分配
- google大牛Jeffrey Dean
- Linux代码风格
- Solution Testing
- Unity--关于中文显示的解决方法
- Unity3D+Kinect OpenNI开发获取身高