【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 ...
随机推荐
- appcan UI
appcan UI 公共类 ([appcanUI框架地址:](http://newdocx.appcan.cn/UI/source) .ub { display: -webkit-box !impor ...
- embed标签 阻止点击事件 让父元素处理点击事件
由于规定页面显示的PDF文件要有固定大小,使得页面风格统一 最开始发现了CSS样式pointer-events 写出如下代码,在360急速浏览器急速模式中访问可在点击PDF控件时可跳转页面 <a ...
- 转 一次完整地http请求
作者:斯巴达克斯 时间:January 11, 2014 分类:WEB 声明:本文章中的说法仅是个人理解总结,不一定完全正确,但是可以有助于理解. 关于HTTP协议可以参考以下: HTTP协议漫谈 h ...
- 解决linux下终端无法输入的假死问题
有时在linux下shell终端中,会突然出现终端应用卡死,无法接受键盘输入, 但是其它分屏, 系统都是正常的.这本来是一个终端的很老的功能, 叫软件流控制(XON/XOFF flow control ...
- python基础===成员访问__len__()和__getitem__()
class A: def __init__(self,*args): self.name = arg pass def __len__(self): return len(self.name) a = ...
- 005 JAVA多线程和并发基础面试问答(转载)
原文链接:http://ifeve.com/java-multi-threading-concurrency-interview-questions-with-answers/ 多线程和并发问题是Ja ...
- hadoop 安装 错误及解决方法
1.ssh 相关问题: rm ~/.ssh/known_hosts //与ssh中的不服 //再重新生成密钥 2.ERROR namenode.NameNode: java.io.IOExceptio ...
- iOS APP程序启动原理
UIApplication 程序启动原理 一个应用程序运行就必须要有一个进程,一个进程至少要有一个线程,我们把这个线程叫做主线程,主线程开启之后会开启一个主运行循环,如果不开启一个运行循环,程序开启了 ...
- Python-生成器/你不知道的点
1.什么是生成器 通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的.而且,创建一个包含100万个元素的列表,不仅占用很大的存储空间,如果我们仅仅需要访问前面几个元素, ...
- ASP.NET Core Module overview模块概述
原文地址:ASP.NET Core Module overview By Tom Dykstra, Rick Strahl, and Chris Ross ASP.NET Core模块(ANCM)让你 ...