模板:数位DP
第一次听说dp还有模板的。。。
当然你要是记忆化搜索的话,就可以有一些套路
这是一个伪代码:
LL Dfs(LL now,限制,LL top){ if(!now) return 判断条件; if(!top && f[now][...]) return f[now][...]; LL Up=top?a[now]:9; LL ret(0); for(LL i=0;i<=Up;++i) ret+=Dfs(now-1,...,top&(i==Up)); if(!top) f[now][...]=ret; return ret; } inline LL Solve(LL x){ LL tot(0); while(x){ a[++tot]=x%10; x/=10; } Dfs(....); return ret; }