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