boj 316

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

 

思路:

s:字符串

dp[n]表示长度为n的字符串可能的密码个数。

对于dp[i],j∈[0,i-1],如果s[j,i]对应的整数大小小于等于255,则dp[i]+=dp[j-1]

注意前导0,输出要mod1234567

代码:

#include<iostream>
using namespace std;

char a[1005];
int b[1005];
int dp[1005];
int pow(int m,int n)
{
	int mul=1;
	for(int i=0;i<n;i++)
		mul=mul*m;
	return mul;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%s",a);
		int len=strlen(a);
		dp[0]=1;
		for(int i=1;i<=len;i++)
		{
			b[i]=a[i-1]-'0';
			dp[i]=dp[i-1];
			int judge = b[i];
			for(int j=i-1;j>0;j--)
			{
				judge+=b[j]*pow(10,i-j);
				if(judge>255)
					break;
				if(b[j]!=0)
					dp[i]+=dp[j-1]%1234567;
			}
		}
		printf("%d\n",dp[len]%1234567);
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值