蒟蒻刚学数位dp 70pts 求调
查看原帖
蒟蒻刚学数位dp 70pts 求调
625380
FriedrichC楼主2022/10/15 10:40

rt,WA on #1 #4 #5

#include<bits/stdc++.h>
#define int long long
using namespace std;
int num[20],dp[20][15][15][2][2][2];
int dfs(int pos,int pre1,int pre2,bool lim,bool zero,bool e,bool f,bool ok)
{
    if(e&&f)return 0;
    if(pos==0)return ok;
    if(!lim&&!zero&&dp[pos][pre1][pre2][e][f][ok]!=-1)return dp[pos][pre1][pre2][e][f][ok];
    int mxd=lim?num[pos]:9;
    int ans=0;
    for(int i=0;i<=mxd;++i)
        ans+=dfs(pos-1 , (zero&&!i)?-1:i , zero?-1:pre1 , lim&&i==mxd , zero&&!i , e||i==8 , f||i==4 , ok||((!zero&&i==pre1&&i==pre2)));
    if(!lim&&!zero)dp[pos][pre1][pre2][e][f][ok]=ans;
    return ans;
}
int solve(int x)
{
    int len=0;
    while(x)num[++len]=x%10,x/=10;
    if(len!=11)return 0;
    return dfs(len,-1,-1,1,1,0,0,0);
}
signed main()
{
    memset(dp,-1,sizeof(dp));
    int a,b;
    cin>>a>>b;
    cout<<solve(b)-solve(a-1)<<endl;
    return 0;
}

2022/10/15 10:40
加载中...