F(x)

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4423    Accepted Submission(s): 1632

Problem Description

For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight as F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 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).
 

Input

The 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 < 109)
 

Output

For 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
 
 

Source

 
 //2016.8.31
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int dp[][], bit[], a, b;//dp[i][j]表示第i位<=j的数目 int F(int a)
{
int ans = , len = ;
while(a)
{
ans += (a%)*(<<len);
len++;
a /= ;
}
return ans;
} int dfs(int pos, int num, int fg)
{
if(pos == -)return num>=;
if(num < )return ;
if(!fg && dp[pos][num]!=-)//记忆化搜索
return dp[pos][num];
int ans = ;
int ed = fg?bit[pos]:;
for(int i = ; i <= ed; i++)
ans+=dfs(pos-, num-i*(<<pos), fg&&i==ed);
if(!fg)dp[pos][num] = ans;
return ans;
} int solve(int b)
{
int len = ;
while(b)
{
bit[len++] = b%;
b /= ;
}
int ans = dfs(len-, F(a), );
return ans;
} int main()
{
int T, kase = ;
cin>>T;
memset(dp, -, sizeof(dp));
while(T--)
{
scanf("%d%d", &a, &b);
int ans = solve(b);
printf("Case #%d: %d\n", ++kase, ans);
} return ;
}

HDU4734(数位dp)的更多相关文章

  1. 【HDU4734】F(x) 【数位dp】

    题意 先定义了一个函数F(X)=An*2^n-1+An-1*2^n-2+.....+A1*1.其中Ai为X的第i位的值.对于每组数据给出了两个整数A,B.问不超过B的数中有多少的F值是不超过F(A)的 ...

  2. 【hdu4734】F(x) 数位dp

    题目描述 对于一个非负整数 $x=​​\overline{a_na_{n-1}...a_2a_1}$ ,设 $F(x)=a_n·2^{n-1}+a_{n-1}·2^{n-2}+...+a_2·2^1+ ...

  3. 【hdu4734】【F(x)】数位dp + 小小的总结一下

    (https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65608478) Problem Description For ...

  4. [hdu4734]F(x)数位dp

    题意:求0~f(b)中,有几个小于等于 f(a)的. 解题关键:数位dp #include<bits/stdc++.h> using namespace std; typedef long ...

  5. hdu4734 F(x)(数位dp)

    题目传送门 F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  6. HDU4734 F(x) 题解 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 题目大意: 对于一个 \(n\) 位十进制数 \(x\) (\(A_nA_{n-1}A_{n-2 ...

  7. [HDU4734] 不要62(数位dp入门)

    >传送门< 题意:统计区间 [a,b] 中不含 4 和 62 的数字有多少个. 思路:数位dp 就是数位上不能有4也不能有连续的62,没有4的话在枚举的时候判断一下,不枚举4就可以保证状态 ...

  8. [HDU4734] F(x)(数位dp+优化)

    >传送门<题意:对于一个有n位(这n位从高位到低位分别是An,An-1,An-2 ... A2,A1)的十进制数,我们定义它的权值F(x)=An*2n-1 + An-1*2n-2 + .. ...

  9. HDU4734 F(x) (数位DP)

    (如此简短的题目给人一种莫名的压迫感......) 题目中定义一个数的权值求解函数:F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1. 观察 ...

随机推荐

  1. IFieldEdit Interface 接口

    Description The IFieldEdit interface is used when creating new fields. You should not use it to modi ...

  2. ZjDroid工具介绍及脱壳详细示例

    前提条件: 1.Root手机一部 2.需要通过Xposed installer(http://dl.xposed.info/latest.apk)安装Xposed Framework; 一.ZjDro ...

  3. [算法] kruskal最小生成树算法

    #include <stdio.h> #include <stdlib.h> #define MAX 100 int N, M; struct Edge { int u,v; ...

  4. ZOJ 3933 Team Formation

    费用流裸题......比赛的时候少写了一句话....导致增加了很多无用的边一直在TLE #include<cstdio> #include<cstring> #include& ...

  5. 关于安装Windows Live Writer后,内存被占满情况解决

    为了方便写博客,昨天安装了Windows Live Writer2012,但是出现了在安装好后还是正常的,第二天一开机就出现了内存被占满的情况,在资源监视器里看了下也没发现有什么问题.想还是重启一下, ...

  6. S3C2440触摸屏驱动详解

    2440的触摸屏转换接口搭载在ADC接口之上,使用上比ADC接口多了一些花样,首先,触摸屏接口有几种转换模式 1. 普通转换模式 单转换模式是最合适的通用ADC转换.此模式可以通过设置ADCCON(A ...

  7. 一起学JUCE之Atomic

    Atomic功能是提供简单的类保持原始值,并且提供对其执行原子操作:Atomic是线程安全的,类型的实现比较简单,就是通过各种措施保证变量的操作达到原子操作,有一点需要注意Atomic使用的时候只支持 ...

  8. git如何正确回滚代码

    git如何正确回滚代码 方法一,删除远程分支再提交 ①首先两步保证当前工作区是干净的,并且和远程分支代码一致 $ git co currentBranch $ git pull origin curr ...

  9. HttpListener 实现web服务端

    1. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste ...

  10. 内网服务器启动报错UNEXPECTED INCONSISTENCY解决方法

    一开始进入系统显示reboot and select proper boot device or insert boot media in selected boot device and press ...