题目传送门

F(x)

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

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
 
Recommend
 
题意:定义F(x),求在[0,m]中F[x]小于F(n)的数的个数
题解:数位dp
代码:
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> PII;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
//head
int T;
int n,m;
int bit[];
int dp[][];
int F(int x)
{
int cnt=;
int len=;
while(x)
{
cnt+=(x%)*(<<len);
x/=;
len++;
}
return cnt;
}
int dfs(int pos,int sta,bool limit)
{
if(pos==-) return sta>=;
if(sta<) return ;
if(!limit&&dp[pos][sta]!=-) return dp[pos][sta];
int ans=;
int up=limit?bit[pos]:;
for(int i=;i<=up;i++)
ans+=dfs(pos-,sta-i*(<<pos),limit&&i==up);
if(!limit) dp[pos][sta]=ans;
return ans;
}
int calc(int x)
{
int len=;
while(x)
{
bit[len++]=x%;
x/=;
}
return dfs(len-,F(n),true);
}
int main()
{
scanf("%d",&T);
int ncase=;
memset(dp,-,sizeof(dp));
while(T--)
{
scanf("%d %d",&n,&m);
printf("Case #%d: ",++ncase);
printf("%d\n",calc(m));
}
return ;
}

hdu4734 F(x)(数位dp)的更多相关文章

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

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

  2. HDU-4734 F(x) 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 注意到F(x)的值比较小,所以可以先预处理所有F(x)的组合个数.f[i][j]表示 i 位数时 ...

  3. 【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+ ...

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

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

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

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

  6. F(x) 数位dp

    Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight ...

  7. HDU4389:X mod f(x)(数位DP)

    Problem Description Here is a function f(x): int f ( int x ) { if ( x == 0 ) return 0; return f ( x ...

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

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

  9. bzoj 3131 [Sdoi2013]淘金(数位DP+优先队列)

    Description 小Z在玩一个叫做<淘金者>的游戏.游戏的世界是一个二维坐标.X轴.Y轴坐标范围均为1..N.初始的时候,所有的整数坐标点上均有一块金子,共N*N块.    一阵风吹 ...

随机推荐

  1. linux--基础知识2

    #超级用户root的家目录是/root ,而普通用户的家目录被存放在/home目录下 cd /目录  切换到指定目录 注意 /  是根目录 linux的一些重要目录 1.bin目录,用来存放常用的可执 ...

  2. uboot tag存储主要部分代码

    https://www.cnblogs.com/pokerface/p/5217106.html     cmd_bootm.c //传递给内核的参数      int do_bootm (cmd_t ...

  3. jQuery ajax上传文件实例

    jQuery ajax上传文件实例 <form id="form" enctype="multipart/form-data"><input ...

  4. 【串线篇】spring boot日志框架

    一.日志框架 小张:开发一个大型系统: 1.System.out.println(""):将关键数据打印在控制台:去掉?写在一个文件? 2.框架来记录系统的一些运行时信息:日志框架 ...

  5. bzoj1875 [SDOI2009]HH去散步 矩阵快速幂

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=1875 题解 如果没有这个"不能立刻沿着刚刚走来的路走回",那么这个题就是一 ...

  6. MYSQL数据库类型与JAVA类型对应表

    MYSQL数据库类型与JAVA类型对应表   MYSQL数据库类型与JAVA类型对应表 类型名称 显示长度 数据库类型 JAVA类型 JDBC类型 索引(int) VARCHAR L+N VARCHA ...

  7. RAC搭建---自己做

    一.本地磁盘是指你本身加上去的磁盘,只能本机使用的.共享磁盘是指可以多台机器同时读取写入.你做RAC就要用到共享存储: 二.ORC分区一般1G*3  数据分区5G*3  ,FRA分区一般5G*3  这 ...

  8. NIO拷贝

  9. CentOS下安装Chrome浏览器中文显示为方框

    执行如下三条命令 yum groupinstall "X Window System" -y yum -y groupinstall chinese-support yum -y  ...

  10. Jmeter的JDBC请求执行多条SQL语句

    注:有mysqlconnector/j 3.1.1以上版本才支持执行多条sql语句 1.     下载jdbc驱动为了连接Mysql数据库,还需要有个jdbc驱动:mysql-connector-ja ...