For a decimal number x with n digits (A nn-1n-2 ... A 21), we define its weight as F(x) = A n * 2 n-1 + A n-1 * 2 n-2 + ... + A 2 * 2 + A 1 * 1. Now you are given two numbers A and B, please calculate how many numbers are there between 0 and B, inclusive, whose weight is no more than F(A).

InputThe first line has a number T (T <= 10000) , indicating the number of test cases. 
For each test case, there are two numbers A and B (0 <= A,B < 10 9)OutputFor every case,you should output "Case #t: " at first, without quotes. The t is the case number starting from 1. Then output the answer.Sample Input

3
0 100
1 10
5 100

Sample Output

Case #1: 1
Case #2: 2
Case #3: 13

题意:给定了一个数字权值计算公式,问0-b中有多少数字f(x)<f(a);

思路:

dp[pos][num]表示在数位pos之后,f(x)小于等于num的数量

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
int dp[][];
int dig[];
int fa;
int dfs(int pos,int num,bool limit){
if(num<){ return ;}
if(pos==-){
return num>=;
}
if(!limit&&dp[pos][num]!=-){ return dp[pos][num];}
int up=limit?dig[pos]:;
int ans=;
for(int i=;i<=up;i++){
ans+=dfs(pos-,num-i*(<<pos),limit&&i==up);
}
if(!limit){dp[pos][num]=ans;}
return ans;
} int solve(int x){
int pos=;
while (x){
dig[pos++]=x%;
x/=;
}
return dfs(pos-,fa,true);
} int cal(int x){
int tmp=,ans=;
while (x){
ans+=(x%)*tmp;
x/=;
tmp<<=;
}
return ans;
}
int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
int cases=;
memset(dp,-,sizeof(dp));
while (T--){ cases++;
int a,b;
scanf("%d%d",&a,&b);
fa=cal(a);
printf("Case #%d: %d\n",cases,solve(b));
}
return ;
}

HDU - 4734 F(x) (数位dp)的更多相关文章

  1. HDU 4734 F(x) ★(数位DP)

    题意 一个整数 (AnAn-1An-2 ... A2A1), 定义 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1,求[0..B]内有多少 ...

  2. HDU 4734 - F(x) - [数位DP][memset优化]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 Time Limit: 1000/500 MS (Java/Others) Memory Lim ...

  3. 【数位DP】 HDU 4734 F(x)

    原题直通车:HDU 4734 F(x) 题意:F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1, 求0.....B中F[x]<=F[A ...

  4. HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...

  5. 题解——HDU 4734 F(x) (数位DP)

    这道题还是关于数位DP的板子题 数位DP有一个显著的特征,就是求的东西大概率与输入关系不大,理论上一般都是数的构成规律 然后这题就是算一个\( F(A) \)的公式值,然后求\( \left [ 0 ...

  6. HDU 4734 F(x) (2013成都网络赛,数位DP)

    F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  7. hdu 4389 X mod f(x) 数位DP

    思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...

  8. HDU 4734 F(x) 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小 ...

  9. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  10. HDU 5787 K-wolf Number 数位DP

    K-wolf Number Problem Description   Alice thinks an integer x is a K-wolf number, if every K adjacen ...

随机推荐

  1. 高通MSM8998 ABL的调试

    高通在MSM8998上引入了UEFI,用来代替LK(Little Kernel).高通UEFI由XBL和ABL两部分组成.XBL负责芯片驱动及充电等核心应用功能.ABL包括芯片无关的应用如fastbo ...

  2. Java获取图片属性

    BufferdImage bfi = ImageIO.read( new File(“d:/file/img.jpg”) ); //获取图片位深度 Int imgBit = bfi.getColorM ...

  3. Puppeteer学习之小试牛刀

    最近有了写文章的动力了,一方面是受到了很多前辈们的启示,另一方面也是为了记录下来更好地学以致用.闲言少叙,先说说Puppeteer是什么. Puppeteer是一个node库,提供了一些用来操作Chr ...

  4. rabbitmq之基本原理及搭建单机环境

    1.RabbitMQ基本原理 1.MQ全称Message Queue,是一种分布式应用程序的通信方法,是消费-生产者模型的典型代表,producer向消息队列中不断写入消息,而另一端consumer则 ...

  5. sql语句修改字段类型和增加字段

    /*修改字段类型*/ ) go /*增加字段和说明*/ ) EXECUTE sp_addextendedproperty N'MS_Description','说明文字',N'user',N'dbo' ...

  6. 使用docker安装mysql和redis

    本文介绍在linux下使用docker安装mysql和redis. 原文地址:代码汇个人博客 http://www.codehui.net/info/59.html 测试环境:centos7.6,do ...

  7. 如何禁止chrome浏览器http自动转成https 【转】

    Chrome 浏览器 地址栏中输入 chrome://net-internals/#hsts 在 Delete domain security policies 中输入项目的域名,并 Delete 删 ...

  8. 既然CPU一次只能执行一个线程,那多线程存在的意义是什么?

    今天看到了一篇文章,终于解除了一直的疑惑.         原文链接:https://www.cnblogs.com/qingbafengliuxia/p/10171638.html CPU的时间是按 ...

  9. zabbix-agent(zabbix-proxy)配置

    PidFile=/var/run/zabbix/zabbix_agentd.pidLogFile=/var/log/zabbix/zabbix_agentd.logLogFileSize=30Serv ...

  10. 360 随身 WiFi3 在 Ubuntu 14.04 下的使用

    由于 360 随身 WiFi3 采用 Mediaek 代号 0e8d:760c 的芯片,目前没有官方或第三方 Linux 驱动,所以造成 Linux 用户的诸多困扰. 本文给出一个迂回的解决方案:在 ...