【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 ...
随机推荐
- hdu 1969 Pie(二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1969 Pie Time Limit: 5000/1000 MS (Java/Others) Me ...
- 代码回滚:Reset、Checkout、Revert 的选择
git reset.git checkout 和 git revert 是你的 Git 工具箱中最有用的一些命令.它们都用来撤销代码仓库中的某些更改,而前两个命令不仅可以作用于提交,还可以作用于特定文 ...
- linux系统下git使用
转载:http://www.cnblogs.com/bear2flymoon/p/4335364.html?ADUIN=563508762&ADSESSION=1430887070&A ...
- monkey测试===Monkey测试策略(系列二)转
Monkey的测试策略 一. 分类 Monkey测试针对不同的对象和不同的目的采用不同的测试方案,首先测试的对象.目的及类型如下: 测试的类型分为:应用程序的稳定性测试和压力测试 测试对象分为:单一a ...
- 计数排序的实现--适用于元素均较小的seq
今天无聊就打算把所有的排序算法都看一遍... 计数排序的时间复杂度是O(n),在算法导论中,用决策树模型中论证了,比较排序的情况为nlogn的复杂度.而计数排序的时间复杂度小于他的原因就是它不需要进行 ...
- SAE如何使用Git
了解Git及远程git仓库 请先看博文<Git入门及上传项目到github中>,弄懂了之后我相信我下面说的就相当于废话了. SAE的git远程仓库就相当于github. 向SAE的远程仓库 ...
- 系统调用wait()
进程一旦调用了 wait,就 立即阻塞自己,由wait自动分析是否当前进程的某个子进程已经退出,如果让它找到了这样一个已经变成僵尸的子进程,wait 就会收集这个子进程的信息, 并把它彻底销毁后返回: ...
- [hadoop][基本原理]zookeeper基本原理
1.简介 https://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/ 2. 数据模型 Zookeeper 会维护一个具有层次关系 ...
- MyBatis3-与Spring 4集成
继续使用前一篇的例子http://www.cnblogs.com/EasonJim/p/7052368.html,实际项目中,通常会用Spring来管理DataSource等.充分利用Spring基于 ...
- Django_admin源码流程
admin.py from django.contrib import admin from . import models """ 通过原生的django admin来 ...