# hdu 3886 - Final Kichiku “Lanlanshu”（数位dp）多校联合

## Final Kichiku “Lanlanshu”

Problem Description
During 2010 summer training, temperlisyer often does problem like this:
“Consider a decimal integer as sequence of digits {D0, D1 … Dn-1} (D0 > 0), if exists such x, y and z, satisfying:

1. Di1<Di(0<i<=x)$D_i-1
2. Di1=Di(x<i<=y)$D_i-1=D_i (x
3. Di1<Di(y<i<=z)$D_i-1
4. Di1>Di(z<i<=n1)$D_i-1>D_i (z

We call this integer “Lanlanshu”, now give you two numbers A and B, calculate how many “Lanlanshu” are in [A, B].“
He solved so many of these and finally get bored, and then get crazy! He decided to make up a problem to put this type of problems to an end.
Give you a string str consists only by ‘/’, ‘-‘ and ‘\’, and its length is l. Consider a decimal integer as sequence of digits {D0, D1 … Dn-1} (D0 > 0), define x0=0, xl=n-1, if exists such x1, x2…xl (x0 < x1 < x2 < … < xl) satisfying:
1. If str[i]=’/’, Dj1<Dj(xi<j<=xi+1)$D_j-1
2. If str[i]=’-’, Dj1=Dj(xi<j<=xi+1)$D_j-1=D_j (x_i
3. If str[i]=’\’, Dj1>Dj(xi<j<=xi+1)$D_j-1>D_j (x_i

We call it Final Kichiku “Lanlanshu”, now give you two numbers A and B, calculate how many Final Kichiku “Lanlanshu” are in [A, B]. This number maybe huge, we only want to now the last 8 digits of the result.

Input
Multiple cases (no more than 100), for each case:
The first line is string str, length is below 100.
The second line contains two integers A and B (0≤Ai≤Bi≤10^100).
Input terminates by EOF.

Output
For each case, output 8 digits representing the last 8 digits of the number of Final Kichiku “Lanlanshu” in [A, B]. If it’s less than 8 digits, fill it with leading zeros.

Sample Input

/\
01221 2012

Sample Output

00000315

Author
temperlsyer

Source
2011 Multi-University Training Contest 5 - Host by BNU

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
const int MOD=1e8;
const int maxn=10;
string A,B;
string st;
int stlen,alen;
int dp[110][110][10];
int dig[110];
string subone(string A)
{
int len=A.size();
if(A[len-1]>'0')
{
A[len-1]-=1;
return A;
}
else
{
int i=len-1;
while(i>=0&&A[i]<='0')A[i]='9',i--;
A[i]-=1;
return A;
}
}
int check(int x,int y,char op)
{
if(op=='/')return x<y;
if(op=='-')return x==y;
return x>y;
}
int dfs(int cur,int e,int z,int pos,int last)
{
if(cur==alen)return pos==stlen;
if(!e&&!z&&dp[cur][pos][last]!=-1)
return dp[cur][pos][last];
int end=e?dig[cur]:9;
int ans=0;
for(int i=0;i<=end;i++)
{
if(z)ans+=dfs(cur+1,e&&i==end,z&&i==0,0,i);
else
{
if(pos<stlen&&check(last,i,st[pos]))
ans+=dfs(cur+1,e&&i==end,0,pos+1,i);
else if(pos>0&&check(last,i,st[pos-1]))
ans+=dfs(cur+1,e&&i==end,0,pos,i);

}
ans%=MOD;
}
if(!e&&!z)dp[cur][pos][last]=ans;
return ans;
}
int solve(string a)
{
memset(dp,-1,sizeof(dp));
int len=a.size();
alen=a.size();
int st=0;
while(a[st]=='0')st++;
for(int i=st;i<len;i++)dig[i]=a[i]-'0';
return dfs(st,1,1,0,0);
}
int main()
{
while(cin>>st)
{
cin>>A>>B;
stlen=st.size();
int len=A.size();
A=subone(A);
printf("%08d\n",(solve(B)-solve(A)+MOD)%MOD);
}
return 0;
}

• 本文已收录于以下专栏：

## HDU 3886 Final Kichiku “Lanlanshu” 数位DP

• wangjie_wang
• 2013年08月31日 16:10
• 530

## hdu 3886 Final Kichiku “Lanlanshu” (数位dp)

http://acm.hdu.edu.cn/showproblem.php?pid=3886 给出一个字符，只含'/'，'-' ，'\' ，表示着一个数上的各位数字按相应字符上升，不变或下降...
• u013081425
• 2014年08月29日 21:30
• 695

## hdu 3886 Final Kichiku “Lanlanshu（数位DP进阶）

• slowlight93
• 2015年03月17日 01:47
• 375

## [数位dp] hdu 3886 Final Kichiku “Lanlanshu”

• wdcjdtc
• 2014年09月26日 19:50
• 793

## 【HDU】3886 Final Kichiku “Lanlanshu” 数位DP

• u013368721
• 2014年11月21日 18:55
• 594

## HDU - 3886 Final Kichiku “Lanlanshu”（数位DP，各种形状模板）

Final Kichiku “Lanlanshu” Problem Description During 2010 summer training, temperlisyer ofte...
• lzc504603913
• 2017年10月12日 13:50
• 73

## hdu_3886_Final Kichiku “Lanlanshu”(数位DP)

• bin_gege
• 2016年07月06日 15:05
• 124

## Final Kichiku “Lanlanshu”

• u012476429
• 2014年07月26日 21:17
• 979

## 2017HDU多校第9场

2017hdu多校第9场题目
• real_Rickys
• 2017年08月23日 13:40
• 249