#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)

H - F(x)的更多相关文章

  1. The Preliminary Contest for ICPC Asia Nanjing 2019( B H F)

    B. super_log 题意:研究一下就是求幂塔函数 %m的值. 思路:扩展欧拉降幂. AC代码: #include<bits/stdc++.h> using namespace std ...

  2. 数位dp H - F(x) HDU - 4734

    http://acm.hdu.edu.cn/showproblem.php?pid=4734 一般数位dp表示的是数的性质,这个题目也是一样,但是我们求出来的是一个函数的值,怎么把这个值转化成一类数, ...

  3. 微软职位内部推荐-Senior Software Development Engineer H/F

    微软近期Open的职位: Microsoft Engineering Center Paris (Xbox Music et Video) : Ingénieur en développement l ...

  4. EPANET头文件解读系列9——VARS.H

    /*************************************************************************            Global Variabl ...

  5. u-boot 2016.05 添加自己的board 以及config.h

    拿到一个uboot 后,我都想添加一个属于自己的board文件以及include/configs/*.h 文件. 如何添加这个些文件,今天来记录一下. 复制一份你所参考的板级文件,比如说board/v ...

  6. Windows常用命令,想要看什么命令直接在全文“CTRL+F”检索(转)

    原文地址:https://www.cnblogs.com/kekec/p/3662125.html 打开"运行"对话框(Win+R),输入cmd,打开控制台命令窗口... 也可以通 ...

  7. f(n)=1-1/2+1/3-1/4...+1/n

    #include <stdio.h>//f(n)=1+1/1+1/2+1/3+...+1/n int main(){ int n,i; double sum=0.0; scanf(&quo ...

  8. 关于$f(x)=\int_0^x\left|\sin\frac1t\right|\text dt$求导的问题

    首先,我们考虑\(f(x)\)在\(\mathbb R\)上都是定义的.根据定义,显然有\(f(0)=0\):其次,对于\(x\neq0\),不妨先设\(x\gt0\),则有在\(t\rightarr ...

  9. 破解SQLServer for Linux预览版的3.5GB内存限制 (RHEL篇)

    微软发布了SQLServer for Linux,但是安装竟然需要3.5GB内存,这让大部分云主机用户都没办法尝试这个新东西 这篇我将讲解如何破解这个内存限制 要看关键的可以直接跳到第6步,只需要替换 ...

随机推荐

  1. 最全的Android源码目录结构详解【转】

    本文转载自:http://blog.csdn.net/yangwen123/article/details/8055025 Android 2.1|-- Makefile|-- bionic     ...

  2. POJ 1611 The Suspects (并查集+数组记录子孙个数 )

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 24134   Accepted: 11787 De ...

  3. 基于BASYS2的VHDL程序与烧写——按键消抖程序

    请尊重作者版权,转载请注明源地址http://www.cnblogs.com/connorzx/p/3548364.html 按键在按下的过程中通常会产生一段时间的抖动,为了消除这种抖动,一般采取两种 ...

  4. html5--5-15 绘制阴影

    html5--5-15 绘制阴影 实例 <!doctype html> <html> <head> <meta charset="utf-8&quo ...

  5. Sublime Text 快捷键及使用技巧的学习整理

    下载和安装(很简单,省略)下载地址 http://www.sublimetext.com/2 1. 有两点需要注意 a) Sublime Text目前稳定的版本是Sublime Text 2,Subl ...

  6. 页面刷新 方法总结 JSP刷新[转]

    1) <meta http-equiv="refresh"content="10;url=跳转的页面"> 10表示间隔10秒刷新一次 2) < ...

  7. BZOJ_3786_星系探索_splay维护出栈入栈序

    BZOJ_3786_星系探索_splay维护出栈入栈序 Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为 ...

  8. [Codeforces 715C] Digit Tree

    [题目链接] https://codeforces.com/contest/715/problem/C [算法] 考虑点分治 一条路径(x , y)合法当且仅当 : d(x) * 10 ^ dep(x ...

  9. ZOJ3496 Assignment

    传送门 这题也是真恶心-- 题目大意是俩公司要运货,每条路有容量上限.然后B公司手里有p个--(技能点?)如果在一条路上放了x个技能点,这条路经过了y个货物,那么B公司就会收x*y的钱.现在要求的是, ...

  10. python3 分布式进程(跨机器)BaseManager(multiprocessing.managers)

    A机器负责发送任务和接受结果: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #ta ...