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:当前处理的位 ...
随机推荐
- Codeforces 1132G Greedy Subsequences [线段树]
洛谷 Codeforces 看到题解那么少就来发一篇吧-- 思路 看完题目一脸懵逼,感觉无从下手. 莫名其妙地想到笛卡尔树,但笛卡尔树好像并没有太大作用. 考虑把笛卡尔树改一下:每个点的父亲设为它的右 ...
- 时间格式化 Date-formatDate
//日期格式化 export function formatDate(date,fmt){ var o = { "M+":date.getMonth() + 1,//月份 &quo ...
- 缺失dll的问题
不小心运行一下什么程序就会出现缺失xxx.dll的问题,太烦了,遇到好多,一直没有记录.现在开始记录,以便日后查看~ 1. api-ms-win-crt-runtime-l1-1-0.dll 64位系 ...
- 信息摘要算法之六:HKDF算法分析与实现
HKDF是一种特定的键衍生函数(KDF),即初始键控材料的功能,KDF从其中派生出一个或多个密码强大的密钥.在此我们想要描述的是基于HMAC的HKDF. 1.HKDF概述 密钥派生函数(KDF)是密码 ...
- Oracle存储过程中跳出循环的写法
注:本文来源于: < Oracle存储过程中跳出循环的写法 > Oracle存储过程中跳出循环的写法 记录exit和return的用法 1:exit用来跳出循环 loop IF V_ ...
- Python yield使用浅析
yield可将一个函数变成生成器,每次调用时,返回yield的结果,下次迭代时,从yield 下条语句开始执行. 一个典型的例子,斐波拉切数列: def fab(max): n, a, b = 0, ...
- Git- 连接远程仓库
如何使用Git 连接远程仓库呢?远程仓库->一般指的是代码托管平台.那就先来瞅瞅三个较熟悉的版本(代码)托管服务平台. 版本(代码)托管服务平台: 码云(gitee.com):是开源中国社区团队 ...
- jquery 获取和设置 select下拉框的值
获取Select : 获取select 选中的 text : $("#ddlRegType").find("option:selected").text(); ...
- LeetCode(89):格雷编码
Medium! 题目描述: 格雷编码是一个二进制数字系统,在该系统中,两个连续的数值仅有一个位数的差异. 给定一个代表编码总位数的非负整数 n,打印格雷码序列.格雷码序列必须以 0 开头. 例如,给定 ...
- 20165314 学习基础和C语言基础调查
技能学习心得 你有什么技能比大多人(超过90%以上)更好?针对这个技能的获取你有什么成功的经验?与老师博客中的学习经验有什么共通之处? 从小我的父母就逼着我学习很多技能,比如钢琴,围棋,书法等,不过很 ...