#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
using namespace std;
typedef long long ll; const int maxn = 1e4+;
int dp[][maxn]; //pos sum
int Max;
int aa[]; int f(int x){
int ans = ;
int cnt = ;
while(x){
ans = ans + x%*cnt;
x /= ;
cnt *= ;
}
return ans;
} int dfs(int pos, int sum, bool limit){
if(pos == -) return sum <= Max; //是否满足条件
if(sum > Max) return ;
if(!limit && dp[pos][Max - sum] != -)
return dp[pos][Max - sum];
int up = limit?aa[pos]:;
int ans = ;
for(int i = ; i <= up;i++){
ans += dfs(pos-, sum+ i*(<<pos), limit&&i == aa[pos]);
}
if(!limit) dp[pos][Max - sum] = ans;
return ans;
} int solve(int x){
int pos = ;
while(x){
aa[pos++] = x%;
x /= ;
}
return dfs(pos-, , true); //最高位是有限制的
} int main(){
memset(dp, -, sizeof dp);
int t;
scanf("%d", &t);
int Case = ;
while(t--){
// memset(dp, -1, sizeof(dp));
Case++;
int a, b;
scanf("%d%d", &a, &b);
Max = f(a);
int ans = solve(b);
printf("Case #%d: %d\n", Case, ans);
}
return ;
}

H - F(x)

最新文章

  1. jQuery size()函数
  2. C#:调用webservice时提示对操作的回复消息正文进行反序列化时出错
  3. swift学习记录之代理
  4. RabbitMq、ActiveMq、ZeroMq 和 kafka 比较
  5. Win32 多线程学习笔记
  6. Codeforces Round #365 (Div. 2) D 树状数组+离线处理
  7. 微信公众平台开发localStorage数据总是被清空
  8. MFC常用类
  9. iOS-iPad开发之SplitViewController简单介绍
  10. seajs打包部署工具spm的使用总结
  11. POJ1458 Common Subsequence 【最长公共子序列】
  12. backbonejs mvc框架
  13. 解决mysql启动失败报1067错误
  14. Java IO详解(四)------字符输入输出流
  15. post插件
  16. ROS(indigo) turtlebot2 + android一些有趣应用
  17. C# 内插字符串与字符串复合格式
  18. 【Codeforces Round 1117】Educational Round 60
  19. delphi’线程新技术 并行计算
  20. ps教程分享:一定要记住这20种PS技术!

热门文章

  1. HTTP Status 405
  2. 不懂不能装懂--邮箱后缀“inc”的含义
  3. Linux集群基础
  4. 配置maven环境变量并安装jar包到本地仓库
  5. 第三篇:python基础之数据类型与变量
  6. JavaScript Constructors
  7. 检测SSL证书很好用的三个网站
  8. haprox动态下线后端主机
  9. P2383 狗哥玩木棒
  10. 关于cuda 环境遇到的问题