蒟蒻刚学数位dp 求调

P2602 [ZJOI2010] 数字计数

@[FriedrichC](/user/625380) 调好了,照着题解调的 ```cpp #include<bits/stdc++.h> #define int long long using namespace std; int dp[15][2][15][2],num[15]; int dfs(int pos,bool lim,int cnt,bool zero,int d) { if(pos==0)return cnt; if(dp[pos][lim][cnt][zero]!=-1) return dp[pos][lim][cnt][zero]; int ans=0; //int mxd=lim?num[pos]:9; for(int i=0;i<10;++i){ if (!lim && i > num[pos]) break; ans+=dfs(pos-1,lim||(i<num[pos]),cnt+((!zero||i)&&(i==d)),zero&&(i==0),d); } dp[pos][lim][cnt][zero]=ans; return ans; } int solve(int x,int d) { int len=0; while(x)num[++len]=x%10,x/=10; memset(dp,-1,sizeof(dp)); return dfs(len,0,0,1,d); } signed main() { int a,b; cin>>a>>b; for(int i=0;i<=9;++i) cout<<solve(b,i)-solve(a-1,i)<<" "; return 0; } ```
by UchihaCelery @ 2022-10-11 18:45:49


@[UchihaCelery](/user/766986) %%
by FriedrichC @ 2022-10-12 12:34:06


@[UchihaCelery](/user/766986) 大佬能帮忙看看我原来的代码哪里错了吗
by FriedrichC @ 2022-10-12 12:36:18


@[FriedrichC](/user/625380) 好像solve里的dfs参数传错了,开始在第len位上,最高位只能枚举到num[len]所以lim是0,其他我再看看
by UchihaCelery @ 2022-10-12 18:15:16


@[FriedrichC](/user/625380) 还有这个 ``` lim&&i==mxd ``` 是不是不太对?我也不确定,您可以看下[这篇](https://www.luogu.com.cn/blog/bestFy0731/solution-p2602)题解,和你思路有点像,我是照着它改的
by UchihaCelery @ 2022-10-12 18:23:17


@[UchihaCelery](/user/766986) 对的吧,我数位dp都是这样写的
by FriedrichC @ 2022-10-12 18:24:57


@[UchihaCelery](/user/766986) 这篇题解的 $issmall$ 的意义和我的 $lim$ 不太一样
by FriedrichC @ 2022-10-12 18:26:40


@[FriedrichC](/user/625380) 啊对不起,理解有点不到位,~~这样的话我也不会调了(╥╯^╰╥)~~
by UchihaCelery @ 2022-10-12 18:33:24


@[UchihaCelery](/user/766986) (哭哭)
by FriedrichC @ 2022-10-12 18:37:33


|