通过这个题目更加深入了解到了数位dp在记忆化搜索的过程中就是实现了没有限制条件的n位数的状态复用。

#include<bits/stdc++.h>
using namespace std; int f2[];
int b[];
int dp[][];
int A; int F(int x)
{
int a[];
int cnt=;
int ret=;
do{
a[cnt]=x%;
x/=;
cnt++;
}while (x);
for (int i=cnt-;i>=;i--)
{
ret=ret*+a[i];
}
return ret;
} int dfs(int pos,int preok,int limit)
{
if (pos==-) return ;
if (preok && dp[pos][limit]!=-) return dp[pos][limit];
int up=preok?:b[pos];
int ans=;
for (int i=;i<=up;i++)
{
if (limit-f2[pos]*i<) continue;
if (i<b[pos]||preok) ans+=dfs(pos-,,limit-f2[pos]*i);
else ans+=dfs(pos-,,limit-f2[pos]*i);
}
if (preok) dp[pos][limit]=ans;
return ans;
} int solve(int n)
{
if (n<) return ;
int cnt=;
int now=n;
do{
b[cnt]=now%;
now/=;
cnt++;
}while (now);
return dfs(cnt-,,F(A));
} int main()
{
memset(dp,-,sizeof(dp));
f2[]=;
for (int i=;i<=;i++) f2[i]=f2[i-]*;
int t;
scanf("%d",&t);
for (int cas=;cas<=t;cas++)
{
int n;
scanf("%d%d",&A,&n);
printf("Case #%d: %d\n",cas,solve(n));
}
return ;
}

最新文章

  1. WPF入门教程系列十九——ListView示例(一)
  2. How to install starDIct on suse OS?
  3. 16-腾讯-intership-面试
  4. 系统间通信(5)——IO通信模型和JAVA实践 下篇
  5. Scalding初探之三:Hadoop实战
  6. bootstrap学习笔记&lt;十一&gt;(导航条)
  7. bzoj2437
  8. eclipse中如何导入jar包
  9. log4Net使用的四个步骤
  10. unexpected problem
  11. SQL Server 数据库所有者
  12. ElasticSearch D3
  13. 初识matplotlib
  14. DataX通过纯Java代码启动
  15. RH阴性血妇女怀孕注意事项
  16. ClassLoader那事儿
  17. mvc项目 ajax post 返回404错误
  18. python中的Process
  19. python学习第9-10天,函数。
  20. Android 二维码扫描/生成

热门文章

  1. Linux命令备忘录: jobs 显示Linux中的任务列表及任务状态命令
  2. 002---tcp/ip五层详解
  3. 深入了解jQuery Mobile-3装载器
  4. PHP.37-TP框架商城应用实例-后台13-商品管理-扩展分类的添加、显示【数据分组】、搜索分类【多对多】
  5. RelativeSource设定绑定方向
  6. Encrypted bootloader (程序BIN文件加密及在线升级)
  7. 每天一个Linux命令(13):apt命令
  8. Ubuntu 首次给root用户设置密码
  9. nmon Analyser分析仪
  10. Tuxedo 介绍与安装