思路:

dp[pos][pre]代表长度为pos的不大于pre的个数

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<map>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 100+5;
int dp[12][200000],a[20],UP;
int F(int x){
int ret = 0,pos = 0;
while(x){
ret += (x % 10) *(1 << pos);
pos++;
x /= 10;
}
return ret;
}
int dfs(int pos,int sum,bool limit){
if(pos == -1) return sum >= 0;
if(sum < 0) return 0;
if(!limit && dp[pos][sum] != -1) return dp[pos][sum];
int top = limit? a[pos] : 9;
int ret = 0;
for(int i = 0;i <= top;i++){
ret += dfs(pos-1,sum-i*(1<<pos),limit && i == top);
}
if(!limit) dp[pos][sum] = ret;
return ret;
}
int solve(int x){
int pos = 0;
while(x){
a[pos++] = x % 10;
x /= 10;
}
return dfs(pos-1,UP,true);
}
int main(){
int k = 1;
memset(dp,-1,sizeof dp);
int A,B;
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&A,&B);
UP = F(A);
printf("Case #%d: %d\n",k++,solve(B));
}
return 0;
}

HDU 4734 (数位DP)题解的更多相关文章

  1. [hdu 4734]数位dp例题

    通过这个题目更加深入了解到了数位dp在记忆化搜索的过程中就是实现了没有限制条件的n位数的状态复用. #include<bits/stdc++.h> using namespace std; ...

  2. hdu 4734 数位dp

    给一个数A (十进制表示形式为AnAn-1An-2 ... A2A1,定义函数 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1,给一个B, ...

  3. hdu 4507 数位dp(求和,求平方和)

    http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...

  4. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. Kuangbin 带你飞 数位DP题解

    以前一直不知道该咋搞这个比较好. 感觉推起来那个数字好麻烦.后来有一种比较好的写法就是直接的DFS写法.相应的ismax表示当前位是否有限制. 数位DP也是有一种类似模版的东西,不过需要好好理解.与其 ...

  6. HDU 4352 XHXJ's LIS HDU(数位DP)

    HDU 4352 XHXJ's LIS HDU 题目大意 给你L到R区间,和一个数字K,然后让你求L到R区间之内满足最长上升子序列长度为K的数字有多少个 solution 简洁明了的题意总是让人无从下 ...

  7. HDU 2089 数位dp/字符串处理 两种方法

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  9. hdu:2089 ( 数位dp入门+模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 数位dp的模板题,统计一个区间内不含62的数字个数和不含4的数字个数,直接拿数位dp的板子敲就行 ...

  10. hdu 3709 数位dp

    数位dp,有了进一步的了解,模板也可以优化一下了 题意:找出区间内平衡数的个数,所谓的平衡数,就是以这个数字的某一位为支点,另外两边的数字大小乘以力矩之和相等,即为平衡数例如4139,以3为支点4*2 ...

随机推荐

  1. Python一键安装全部依赖包

    requirements.txt用来记录项目所有的依赖包和版本号,只需要一个简单的pip命令就能完成. pip freeze >requirements.txt 然后就可以用 pip insta ...

  2. python排序函数sort()与sorted()区别

    sort是容器的函数:sort(cmp=None, key=None, reverse=False) sorted是python的内建函数:sorted(iterable, cmp=None, key ...

  3. (转)使用git stash解决git pull时的冲突

    在使用git pull代码时,经常会碰到有冲突的情况,提示如下信息: error: Your local changes to 'c/environ.c' would be overwritten b ...

  4. [LeetCode] 529. Minesweeper_ Medium_ tag: BFS

    Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representin ...

  5. [LeetCode] 628. Maximum Product of Three Numbers_Easy

    Given an integer array, find three numbers whose product is maximum and output the maximum product. ...

  6. [LeetCode] 561. Array Partition I_Easy tag: Sort

    Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1 ...

  7. Summary: Java Inheritance

    In this tutorial we will discuss about the inheritance in Java. The most fundamental element of Java ...

  8. sql server 中的分区函数用法(partition by 字段)

    partition  by关键字是分析性函数的一部分,它和聚合函数不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录,partition  by用于给结果集分组,如果没 ...

  9. 电子地图/卫星地图下载并转存为jpg图片

    1.下载水经注万能地图下载器破解版 http://download.csdn.net/download/hyb2012/8714725,此软件为绿色免安装且免注册 2.下载后解压缩后,运行sgwn.e ...

  10. HashMap(JDK1.9)详解

    一.HashMap的概念. 1.HashMap类的继承实现关系如下:因此HashMap的功能有:可序列化.可克隆等功能. 2.HashMap的数据结构:数组+链表+红黑树. 3.键值对的存储方案:第一 ...