hdu 3886 - Final Kichiku “Lanlanshu”(数位dp)多校联合

原创 2015年07月06日 21:03:43

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)
  2. Di1=Di(x<i<=y)
  3. Di1<Di(y<i<=z)
  4. Di1>Di(z<i<=n1)

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)
2. If str[i]=’-’, Dj1=Dj(xi<j<=xi+1)
3. If str[i]=’\’, Dj1>Dj(xi<j<=xi+1)

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

题意: A,B之间有多少个数,满足给定字符串的趋势
思路:dp[cur][pos][last]表示处理到当前为止,满足趋势字符串到pos位置,上一位是last的有多少个

#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

传送门:【HDU】3886 Final Kichiku “Lanlanshu” 题目分析:要求满足所给字符串

hdu_3886_Final Kichiku “Lanlanshu”(数位DP)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3886 题意:这题的题意有点晦涩难懂,大概意思就是给你一个区间,让你找一些满足递增递减条件的数,举个列:...

Final Kichiku “Lanlanshu”

至今也没看懂题目叙述。。。弱菜,看别人程序看懂题意得。。。 给一串字符串,包含‘/’ ‘\’ ‘-’三种,分别表示下一个数比当前大,小,相等。要求出[a, b]区间内,满足要求的数有多少个:要...

多校第6场 HDU 3893&&JLU Drawing Pictures(数位DP变形,矩阵连乘)

题目的要求是用1-6六种颜色排成一列 而且必须对称。相邻不同色。不出现123456 可以肯定的是n偶数的时候必然无解, 因为最中心两个无法满足相邻不同色的要求   对于n奇数的情况因...

hdu 5406 2015 多校联合训练赛#10 dp

CRB and Apple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T...

hdu 4632 Palindrome subsequence 区间dp 多校联合训练第四场

注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字符串中[i,j]位置中出现的回文子序列的个数,有递推关系: 当 第i个字符与第j个字符不相等时有dp[i]...

【HDU 4905 多校联合】The Little Devil II【DP+四边形不等式优化】

题意:给出一个数列,每次你可以选择相邻的两个数字进行求GCD,ranho

【HDU 4901 多校联合】The Romantic Hero【DP】

题意:给出一个序列,从从选出两个不为空的集合S T,S

HDU/HDOJ 3944 DP? 多校联合11 电子科大 lucas定理

DP? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 128000/128000 K (Java/Others) Total ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)