思路:

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. Vue打开新页面的方法

    let routeData = this.$router.resolve({ name: "detail", query: {goodsId:'1111'} }); window. ...

  2. mac chrome 驱动配置

    将解压后的chromedriver移动到/usr/local/bin目录下

  3. mysql 表基本增删查改

    对表的操作是在某个数据库下才能进行的,所以要先选择数据库 "use 数据库名;" 1.创建数据表 1)"create table 表名 (字段1  类型  [约束],  ...

  4. 论存储IOPS和Throughput吞吐量之间的关系

    论存储IOPS和Throughput吞吐量之间的关系 http://www.csdn.net/article/2015-01-14/2823552 IOPS和Throughput吞吐量两个参数是衡量存 ...

  5. 从xtraback 备份文件中 单独恢复一张 innodb 表

    从xtraback 备份文件中 单独恢复一张 innodb 表 http://blog.sina.com.cn/s/blog_445e807b0101dbgw.html 能够恢复一张表的前提是独立表空 ...

  6. 用Servlet获取表单数据

    用Servlet获取表单数据 在webroot下新建userRegist2.jsp 代码如下: <%@ page contentType="text/html;charset=gb23 ...

  7. PAT 1045 Favorite Color Stripe[dp][难]

    1045 Favorite Color Stripe (30)(30 分) Eva is trying to make her own color stripe out of a given one. ...

  8. linux 常用清理或备份文件命令

    find /data/tmp/confluence/backups/ -type f -mtime +7 -exec rm -f {} \; ##查找创建超过7天的文件并强制删除 cp /data/a ...

  9. vs2015 相关

    VS2015一共有3个版本,Visual Studio Community(社区版).Visual Studio Professional(专业版).Visual Studio Enterprise( ...

  10. jmeter处理带表单的接口请求

    如何用jmeter处理带选项的表单接口请求 下面是用到了F12 抓包的处理方法 下图是直接手动在页面上请求的结果 下面就是采用F12抓包抓到url 和FormData 分别把上面获取的url和Form ...