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. 如何删除要素类 IFeatureWorkspace 接口介绍(1)

    如何删除要素类 要想删除一个要素类,那么必须先得到这个,在得到这个要素类的时候,我们要学习一个新的接口IFeatureWorkspace. IFeatureWorkspace  接口介绍 这个接口主要 ...

  2. phpstrom 快捷键

    常用的PHPStorm快捷键:ctrl+j 插入活动代码提示ctrl+alt+t 当前位置插入环绕代码alt+insert 生成代码菜单ctrl+q 查看代码注释ctrl+d 复制当前行ctrl+y ...

  3. ural1628 White Streaks

    White Streaks Time limit: 1.0 secondMemory limit: 64 MB The life of every unlucky person has not onl ...

  4. Bessie Goes Moo

    Bessie Goes Moo 题目描述 Farmer John and Bessie the cow love to exchange math puzzles in their free time ...

  5. PAT (Advanced Level) 1010. Radix (25)

    撸完这题,感觉被掏空. 由于进制可能大的飞起..所以需要开longlong存,答案可以二分得到. 进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid ...

  6. JAVA中浅复制与深复制 - coolmist - ITeye技术网站

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  7. (简单) POJ 3268 Silver Cow Party,Dijkstra。

    Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to atten ...

  8. displayport-2

    上一章讲述了display-port的硬件连接,今天来说说协议层 图中可以看到,最底层是物理层,上层是连接服务层,提供的服务包括同步数据传输服务,aux链接服务,aux设备数据传输服务,在设备端也一样 ...

  9. R语言实战(五)方差分析与功效分析

    本文对应<R语言实战>第9章:方差分析:第10章:功效分析 ================================================================ ...

  10. DataTable distinct 去重复

    有时我们需要从DataTable中抽取Distinct数据,以前总是以对DataTable进行foreach之类纯手工方式获取. 近来发现DataView可以帮我们直接获取Distinct数据,汗一个 ...