beautiful number 数位dp
题意: 求高位往低位递减且 高位%低位==0(相邻) 数字数量
唯一要注意的就是前导零!!!!!!(正因为这个前导零 一开始的pre设置为0 )
比如 11 10 09 08 07 06 05 .。。。。说明要判断前导零
#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define ll long long
#define REP(i,N) for(int i=0;i<(N);i++)
#define CLR(A,v) memset(A,v,sizeof A)
//////////////////////////////////
#define inf 0x3f3f3f3f
#define N 10+5
ll dp[N][];
ll a[N]; ll dfs(int pos,int pre, bool lead,bool limit )
{
if(!pos)return ; if(!limit&&!lead&&dp[pos][pre]!=-)return dp[pos][pre];
ll ans=;
int up=limit?a[pos]:;
rep(i,,up)
{
if(lead||pre>=i&&i&&pre%i==)
ans+=dfs(pos-,i, lead&&i==,limit&&i==a[pos]);
}
if(!limit&&!lead)dp[pos][pre]=ans;
return ans;
}
ll solve(ll x)
{
int pos=;
while(x)
{
a[++pos]=x%;
x/=;
}
return dfs(pos,,true,true);
}
int main()
{
int cas;
RI(cas);
CLR(dp,-);
while(cas--)
{
ll a,b;
cin>>a>>b;
printf("%lld\n",solve(b)-solve(a-));
}
return ;
}
beautiful number 数位dp的更多相关文章
- beautiful number 数位DP codeforces 55D
题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...
- HDU 5179 beautiful number 数位dp
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contes ...
- FZU2179/Codeforces 55D beautiful number 数位DP
题目大意: 求 1(m)到n直接有多少个数字x满足 x可以整出这个数字的每一位上的数字 思路: 整除每一位.只需要整除每一位的lcm即可 但是数字太大,dp状态怎么表示呢 发现 1~9的LCM 是2 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 多校5 HDU5787 K-wolf Number 数位DP
// 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- CodeForces - 55D - Beautiful numbers(数位DP,离散化)
链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
随机推荐
- bootstrap排列顺序
写在 typora 的笔记 复制过来排版很丑,所以截图算了..
- MySQL笔记二
Ø function 函数 函数的作用比较大,一般多用在select查询语句和where条件语句之后.按照函数返回的结果, 可以分为:多行函数和单行函数:所谓的单行函数就是将每条数据进行独立的计算,然 ...
- python HTML报告
http://www.cnblogs.com/puresoul/p/7490737.html # coding:utf-8import timeimport unittestimport HTMLTe ...
- iOS -- Effective Objective-C 阅读笔记 (1)
1: 在类的头文件中尽量 少 的引用其他头文件,尽量用 @class xxxxxx; 理解: 当你创建了一个 A 类,这个类又 需要具有 B 类的实例, 你可以直接为 A 类添加 B 类类型的 属性, ...
- swift 学习- 13 -- 下标
// 下标 可以定义在 类, 结构体, 和 枚举 中, 是访问集合, 列表或 序列中元素的快捷方式, 可以使用下标的索引, 设置 和 获取值, 而不需要再调用对应的存取方法, 举例来说, 用下标访问一 ...
- Modbus库开发笔记之七:Modbus其他辅助功能开发
前面开发了各种应用,但是却一直没有提到一个问题,你就是对具体的数据进行读写操作.对于Modbus来说标准的数据有4种:线圈数据(地址:0000x).输入状态量数据(地址:1000x).保持寄存器数据( ...
- Oracle11g 新功能
本文来源:<oacle11g 从入门到精通> 明日科技 Oracle11g 新功能 1:增强信息生命周期管理和储存管理能力 2:全面回忆数据变化 3:最大限度提高信息可用性 4:Oracl ...
- 基于vue-cli3的vue项目移动端样式适配,lib-flexible和postcss-px2rem
1,安装 flexible和 postcss-px2rem(命令行安装) npm install lib-flexible --save npm install postcss-px2rem --sa ...
- nginx(一)之默认配置文件
首先是nginx.conf vim /etc/nginx/nginx.conf user nginx; // 设置nginx服务的系统使用用户 worker_processes 1; // 工作进程数 ...
- HTML&javaSkcript&CSS&jQuery&ajax(十)
HTML 1.SVG直接嵌入HTML网页 ,SVG 是使用XML描述2D图像的语言,Canvas通过JavaScript来绘制2D <svg xmlns="http://www.w3. ...