思路:

dp[pos][pre]代表长度为pos的不大于pre的个数

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 100+5;
int dp[12][200000],a[20],UP;
int F(int x){
int ret = 0,pos = 0;
while(x){
ret += (x % 10) *(1 << pos);
pos++;
x /= 10;
}
return ret;
}
int dfs(int pos,int sum,bool limit){
if(pos == -1) return sum >= 0;
if(sum < 0) return 0;
if(!limit && dp[pos][sum] != -1) return dp[pos][sum];
int top = limit? a[pos] : 9;
int ret = 0;
for(int i = 0;i <= top;i++){
ret += dfs(pos-1,sum-i*(1<<pos),limit && i == top);
}
if(!limit) dp[pos][sum] = ret;
return ret;
}
int solve(int x){
int pos = 0;
while(x){
a[pos++] = x % 10;
x /= 10;
}
return dfs(pos-1,UP,true);
}
int main(){
int k = 1;
memset(dp,-1,sizeof dp);
int A,B;
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&A,&B);
UP = F(A);
printf("Case #%d: %d\n",k++,solve(B));
}
return 0;
}

最新文章

  1. 深入理解DOM事件类型系列第四篇——剪贴板事件
  2. u-boot FIT image介绍_转自“蜗窝科技”
  3. Webwork 学习之路【01】Webwork与 Struct 的前世今生
  4. 16.检查是否为BST
  5. jQuery 写的幻灯左右切换插件
  6. 启动hadoop报192.168.1.151: Address 192.168.1.151 maps to node1, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
  7. caches 文件夹删除
  8. select选项框特效
  9. 加解密算法二:非对称加解密及RSA算法的实现
  10. HTML XML XHTML DHTML区别与联系
  11. linux笔记2.25
  12. 刚写好的读取多网卡IP地址的函数
  13. Javascript使用postMessage对iframe跨域通信
  14. windows程序设计(四)
  15. linux命令(方可)
  16. Android APK安装过程学习笔记
  17. ASP.NET Core 和 ASP.NET Framework 共享 Identity 身份验证
  18. docker之数据卷管理
  19. 让IIS支持10万并发
  20. MySQL -- 全文检索(查询扩展检索)

热门文章

  1. java动态加载
  2. Redis添加历史浏览记录
  3. list的方法、操作
  4. sql优化 性能快速定位
  5. OA系统部署短信过程
  6. api文档生成器apidoc的安装和使用
  7. PAT 1028 List Sorting[排序][一般]
  8. 使用gunicorn部署Flask项目
  9. python 多线程小练习
  10. 树莓派3B新版raspbian系统换国内源