【hdu4734】【F(x)】数位dp + 小小的总结一下
(https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65608478)
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
30 1001 105 100
Sample Output
Case #1: 1Case #2: 2Case #3: 13
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int f[][],a,b,len,orz[],sum,mi[]; int dfs(int pos,int pre,bool limit){
if(pos==){
if(pre<=sum) return ;
return ;
}
if((!limit)&&f[pos][sum-pre]!=-) return f[pos][sum-pre];
int st=limit?orz[pos]:;
int ans=;
for(int i=;i<=st;i++)
if(pre+i*mi[pos]<=sum) ans+=dfs(pos-,pre+i*mi[pos],limit&&i==st);
if(!limit) f[pos][sum-pre]=ans;
return ans;
}
int main(){
memset(f,-,sizeof(f));
mi[]=;
for(int i=;i<=;i++) mi[i]=mi[i-]*;
int t;
scanf("%d",&t);
for(int k=;k<=t;k++){
scanf("%d%d",&a,&b);
sum=;
for(int i=a,j=;i;i/=,j++) sum+=mi[j]*(i%);//printf("sum=%d\n",sum);
for(len=,b;b;b/=) orz[++len]=b%;
printf("Case #%d: %d\n",k,dfs(len,,));
}
return ;
}
【hdu4734】【F(x)】数位dp + 小小的总结一下的更多相关文章
- [hdu4734]F(x)数位dp
题意:求0~f(b)中,有几个小于等于 f(a)的. 解题关键:数位dp #include<bits/stdc++.h> using namespace std; typedef long ...
- hdu4734 F(x)(数位dp)
题目传送门 F(x) Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU-4734 F(x) 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 注意到F(x)的值比较小,所以可以先预处理所有F(x)的组合个数.f[i][j]表示 i 位数时 ...
- 【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+ ...
- hdu 4389 X mod f(x) 数位DP
思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...
- HDU 4734 F(x) ★(数位DP)
题意 一个整数 (AnAn-1An-2 ... A2A1), 定义 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1,求[0..B]内有多少 ...
- F(x) 数位dp
Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight ...
- 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 ...
- HDU 4734 - F(x) - [数位DP][memset优化]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 Time Limit: 1000/500 MS (Java/Others) Memory Lim ...
随机推荐
- 【HMOI】小C的填数游戏 DP+线段树维护
[题目描述] 一个长为n的序列,每个元素有一个a[i],b[i],a[i]为0||1,每个点和他相邻的两个点分别有两条边,权值为cost1[i],cost2[i],对于每个区间l,r,我们可以给每一个 ...
- python进行机器学习(二)之特征选择
毫无疑问,解决一个问题最重要的是恰当选取特征.甚至创造特征的能力,这叫做特征选取和特征工程.对于特征选取工作,我个人认为分为两个方面: 1)利用python中已有的算法进行特征选取. 2)人为分析各个 ...
- Java垃圾收集算法
算法名称 过程 优缺点 1. 标记-清除算法 (Mark-Sweep) 分为两个阶段: 1.首先标记出所有需要回收的对象: 2.在标记完成后统一回收所有被标记的对象. 缺点: 1.效率问题:标记和清除 ...
- U-Boot启动过程完全分析<转>
转载自:http://www.cnblogs.com/heaad/archive/2010/07/17/1779829.html 1.1 U-Boot工作过程 U-Boot启动内核的过程可 ...
- 【bzoj4486】【JSOI2015】串分割
老省选题了. 首先考虑怎么比较超长数字的大小? 参见UTR1的那道题 先比size,然后比较字典序即可. 接下来考虑下切割的问题. 因为要将字符串切割成k份,所以这个字符串只会存在n/k个本质不同的起 ...
- HTML5API(2)
四.文件API 1.概述 H5允许JS有条件的读取客户端文件 允许读取的文件:1.待上传的文件2.拖进浏览器的文件 多文件上传设置属性multiple 过滤上传文件类型 设置accept属性 acce ...
- Oracle事务处理
原文转自:(http://www.cnblogs.com/ITtangtang/archive/2012/04/23/2466554.html) 一.事务概念事务用于保证数据的一致性,它由一组相关的d ...
- DRF的@action装饰器
# 转自:http://www.cnblogs.com/zhzhlong/p/9325180.html 视图集中附加action的声明 from rest_framework.decorators i ...
- linux命令(39):ss命令
ss是Socket Statistics的缩写.顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容.但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信 ...
- 【hdoj_1085】Holding Bin-Laden Captive![母函数]
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1085 可以这样理解题意:给出1元,2元和5元的三种硬币若干,每种硬币数量给出,现在可以从所有的硬币中,选出 ...