【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 ...
随机推荐
- Select 使用不当引发的core,你应该知道的
排查一个死机问题,搞了好几天时间,最终确定原因:最终确定问题原因,在此分享一下: 第一步:常规根据core文件查看栈信息,gdb –c core xxxx 如下rip不正确,指令地址错乱,栈信息已破坏 ...
- 模型验证与模型集成(Ensemble)
作者:吴晓军 原文:https://zhuanlan.zhihu.com/p/27424282 模型验证(Validation) 在Test Data的标签未知的情况下,我们需要自己构造测试数据来验证 ...
- Python模块学习 - click
Click模块 click模块是Flask的作者开发的一个第三方模块,用于快速创建命令行.它的作用与Python标准库的argparse相同,但是,使用起来更简单. click是一个第三方库,因此使用 ...
- 浅谈C语言中的强符号、弱符号、强引用和弱引用【转】
转自:http://www.jb51.net/article/56924.htm 首先我表示很悲剧,在看<程序员的自我修养--链接.装载与库>之前我竟不知道C有强符号.弱符号.强引用和弱引 ...
- 【快速玩转Source Filmmaker】用黑科技做出自己的OC和想要的模型
[快速玩转Source Filmmaker]用黑科技做出自己的OC和想要的模型https://tieba.baidu.com/p/4154097168
- PBFT算法的相关问题
PBFT(99.02年发了两篇论文)-从开始的口头算法(指数级)到多项式级 要求 n>3f why: 个人简单理解:注意主节点是可以拜占庭的,从节点对于(n,v,m)的投票最开始也是基于主节点给 ...
- 2015多校第6场 HDU 5358 First One 枚举,双指针
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5358 题意:如题. 解法:观察式子发现,由于log函数的存在,使得这个函数的值域<=34,然后我 ...
- js获取jsp上下文地址
参考自博客:http://blog.csdn.net/lanchengxiaoxiao/article/details/7445498
- 关于springMVC转换json出现的异常
jackson-core-asl-1.9.0.jar,jackson-mapper-asl-1.9.0.jar两个包 并且在controller中有如下代码 @RequestMapping(value ...
- chain模块将两个列表合并
示例代码 from itertools import chain v1 = [11,22,33] v2 = ['a','b','c'] for item in chain(v1,v2): print( ...