#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. Python序列——序列操作

    Python中的序列包括,字符串.列表.元组.本文介绍序列的通用操作. 1. 切片中的None >>> s = 'abcdefg' >>> for i in ran ...

  2. Codeforces Round #402 (Div. 2) D String Game —— 二分法

    D. String Game time limit per test 2 seconds memory limit per test 512 megabytes input standard inpu ...

  3. Redis缓存服务搭建及实现数据读写 - Eric.Chen

    发现博客园中好多大牛在介绍自己的开源项目是很少用到缓存,比如Memcached.Redis.mongodb等,今天得空抽时间把Redis缓存研究了一下,写下来总结一下,跟大家一起分享 一下.由于小弟水 ...

  4. HDFS namenode 高可用(HA)搭建指南 QJM方式 ——本质是多个namenode选举master,用paxos实现一致性

    一.HDFS的高可用性 1.概述 本指南提供了一个HDFS的高可用性(HA)功能的概述,以及如何配置和管理HDFS高可用性(HA)集群.本文档假定读者具有对HDFS集群的组件和节点类型具有一定理解.有 ...

  5. 关于Froala Editor的简单使用

    1.添加样式表 <!-- 核心样式表 --> <link rel="stylesheet" href="${ctx}/resources/froala_ ...

  6. 我的CSDN博客

    从csdn搬过来的: csdn地址:http://blog.csdn.net/WR_technology

  7. boost replace_if replace_all_regex_copy用法

    #include <boost/algorithm/string.hpp> // for is_any_of #include <boost/range/algorithm/repl ...

  8. slice 和 splice 区别

    splice() 方法与 slice() 方法的作用是不同的,splice() 方法会直接对数组进行修改. slice(start,end)  ; start 必需.规定从何处开始选取.如果是负数,那 ...

  9. MongoDB 3.2复制集单节点部署(四)

    MongoDB在单节点中也可以做复制集,但是仅限于测试实验,最大的好处就是部署方便快速,可以随便添加新节点,节省资源.在这里我使用的是MongoDB 3.2版本进行复制集实验(但MongoDB配置文件 ...

  10. AtCoder Grand Contest 006 C:Rabbit Exercise

    题目传送门:https://agc006.contest.atcoder.jp/tasks/agc006_c 题目翻译 数轴上有\(N\)只兔子,从\(1\)到\(N\)编号,每只兔子初始位置是\(x ...