HDU - 4734 F(x) (数位dp)
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)的更多相关文章
- HDU 4734 F(x) ★(数位DP)
题意 一个整数 (AnAn-1An-2 ... A2A1), 定义 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1,求[0..B]内有多少 ...
- HDU 4734 - F(x) - [数位DP][memset优化]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 Time Limit: 1000/500 MS (Java/Others) Memory Lim ...
- 【数位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 ...
- HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛
普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...
- 题解——HDU 4734 F(x) (数位DP)
这道题还是关于数位DP的板子题 数位DP有一个显著的特征,就是求的东西大概率与输入关系不大,理论上一般都是数的构成规律 然后这题就是算一个\( F(A) \)的公式值,然后求\( \left [ 0 ...
- HDU 4734 F(x) (2013成都网络赛,数位DP)
F(x) Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- hdu 4389 X mod f(x) 数位DP
思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...
- 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的时候的个数,然后需要预处理下小 ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- 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 ...
随机推荐
- 升级WIN10 (9879)后IE无响应的解决办法
身为程序猿,当然有了新系统就要尝尝鲜,有WIN8时,哥是朋友圈第一个用的,有WIN8.1时哥也是第一个升级的. 现在WIN10来了,当然也得赶紧尝尝鲜.直接下载了 9879版的预览版本安装. 要说WI ...
- Gulp 前端优化
使用方法: 下载 node.js , https://nodejs.org/en/,并安装 msi 一下命令都属于 dos 命令 node -v,npm -v,检验是否下载成功(出现版本号) 将 np ...
- 基于Django 的 FreeSwitch 开源GUI 管理系统 YouPBX
YouPBX YouPBX 是一个强大 FreeSwift (电话软交换系统) 的管理GUI系统,基于Django开发,功能全面,体验友好,可以基于此项目做一个完善的IPPBX系统.呼叫中心应用等 项 ...
- 解决Geoserver请求跨域的几种思路
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景描述 跨域问题是浏览器同源安全制引起的特别常见的问题.不同前端语 ...
- arcgis api 3.x for js 入门开发系列十五台风轨迹
前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...
- DVWA 黑客攻防实战(十五) 绕过内容安全策略 Content Security Policy (CSP) Bypass
看到标题,是否有点疑惑 CPS 是什么东东.简单介绍一下就是浏览器的安全策略,如果 标签,或者是服务器中返回 HTTP 头中有 Content-Security-Policy 标签 ,浏览器会根据标签 ...
- MongoDB 基础(2019年开篇)
MongoDB基础知识: 1.什么是MongoDB NoSQL(NoSQL=Not Only SQL),意即"不仅仅是SQL". MongoDB是一个介于关系数据库和非关系数据库之 ...
- oracle异地备份
一.安装oracle客户端 右键以管理员身份运行 选择管理员 跳过软件更新 选择语言,默认中文 指定安装位置 检查当前环境 安装 二.使用exp命令备份 exp 用户名/密码@IP地址/数据库 own ...
- Exception in thread "main" org.I0Itec.zkclient.exception.ZkAuthFailedException: Authentication failure is thrown while creating kafka topic
Exception in thread "main" org.I0Itec.zkclient.exception.ZkAuthFailedException: Authentica ...
- SpringBoot中使用JNnit4(一)之Mockito的使用
经过入门篇,可以编写出一个简单的测试用例. 这篇讲的是BDDMockito的使用. BDDMockito用于测试时进行打桩处理:通过它可以指定某个类的某个方法在什么情况下返回什么样的值. 在单元测试时 ...