$dp[x][p][pp]$表示第x位,当前已有数字mod 2520(1~9数字的lcm)为p,当前各位数字的lcm为pp

观察到数组太大,考虑压缩,第三维lcm最多只有9个数字,打表发现最多只有48个状态,压掉第三维即可

打表用一个状压然后set维护(广搜也可以)即可

有一个坑点:题目里似乎没有说关于0的事情(即数字里出现0)但是有人在CF上打这个比赛的时候问了出题人,碰到0不要管即可!!!

打表代码:

 set<int>s;
inline void Make(int x){
int ans=;
for(int i=;i<;i++){
if(((<<i)&x)) ans=lcm(ans,i+);
}s.insert(ans);
}
inline void States_Maker(){
int ans=;
for(int i=;i<(<<);i++)Make(i);
while(!s.empty()){
cout<<*s.begin()<<",";
s.erase(s.begin());
}
}

解题代码:

 #include<bits/stdc++.h>
#define int long long
#define writeln(x) write(x),puts("")
#define writep(x) write(x),putchar(' ')
using namespace std;
inline int read(){
int ans=,f=;char chr=getchar();
while(!isdigit(chr)){if(chr=='-') f=-;chr=getchar();}
while(isdigit(chr)){ans=(ans<<)+(ans<<)+chr-;chr=getchar();}
return ans*f;
}void write(int x){
if(x<) putchar('-'),x=-x;
if(x>) write(x/);
putchar(x%+'');
}const int M = ,State = ;
int f[M][][State],T,n,a[M],l,r,Pos[],S[State]={,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
inline int gcd(int x,int y){return __gcd(x,y);}
inline int lcm(int x,int y){if(x==)return y;if(y==)return x;return x*y/gcd(x,y);}
int dfs(int x,int p,int pp,bool lim){
if(!x)return (p%pp==)?():();
if(!lim&&p!=-&&pp!=-&&f[x][p][Pos[pp]]!=-)return f[x][p][Pos[pp]];
int ans=,up=lim?a[x]:;
for(int i=;i<=up;i++)ans+=dfs(x-,(p*+i)%,lcm(pp,i),lim&&a[x]==i);
if(!lim)f[x][p][Pos[pp]]=ans;
return ans;
}
inline int Solve(int x){
int len=;
while(x)a[++len]=x%,x/=;
return dfs(len,,,);
}
signed main(){
memset(f,-,sizeof(f));
for(int i=;i<=;i++)Pos[S[i]]=i;
T=read();
while(T--)l=read(),r=read(),writeln(Solve(r)-Solve(l-));
return ;
}

【数位DP】CF55D Beautiful numbers的更多相关文章

  1. [暑假集训--数位dp]cf55D Beautiful numbers

    Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer numb ...

  2. 【数位dp】Beautiful Numbers @2018acm上海大都会赛J

    目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...

  3. 洛谷 CF55D Beautiful numbers 解题报告

    CF55D Beautiful numbers 题意 \(t(\le 10)\)次询问区间\([l,r](1\le l\le r\le 9\times 10^{18})\)中能被每一位上数整除的数的个 ...

  4. cf55D. Beautiful numbers(数位dp)

    题意 题目链接 Sol 看到这种题就不难想到是数位dp了. 一个很显然的性质是一个数若能整除所有位数上的数,则一定能整除他们的lcm. 根据这个条件我们不难看出我们只需要记录每个数对所有数的lcm(也 ...

  5. CF55D Beautiful numbers (数位dp)

    题目链接 题解 一个数能被一些数整除,那么一定被这些数的\(lcm\)整除 那么我们容易想到根据\(lcm\)设状态 我们可以发现有用的\(lcm\)只有\(48\)个 那么按照一般的数位\(dp\) ...

  6. CF55D Beautiful numbers 题解

    题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...

  7. CF55D Beautiful numbers

    题目链接 题意 定义一个数字\(x\)是\(beautiful\ number\)当且仅当\(x\)可以被其十进制表示下所有非\(0\)位置的数整除. 例如\(24\)是一个\(beautiful\ ...

  8. [暑假集训--数位dp]LightOj1205 Palindromic Numbers

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  9. 数位dp(Balanced Numbers )

    题意:一个数,如果满足奇数的数字出现偶数次,偶数的数字出现奇数次, 就是符合的数,注比如:12313  就满足,因为1 3出现了偶数次.2出现了奇数次 思路,对于这道题,就是状态压缩加dp: 对于一个 ...

随机推荐

  1. pytest_fixture--scope="session"

    import pytest@pytest.fixture(scope="session")def login(): print("\n输入用户名密码登陆! configt ...

  2. 判断字符串是否为JSON

    function isJSON(str) { if (typeof str == 'string') { try { var obj=JSON.parse(str); if(typeof obj == ...

  3. canvas-nest.js 设置网页背景

    只需要在HTML,body中加如这行代码就可以实现效果,可以在color中修改颜色 <!DOCTYPE html> <html> <head> <meta c ...

  4. json条件查询

    完整Demo <html> <head> <script type="text/javascript" src="http://www.w3 ...

  5. JavaWeb学习篇之----自定义标签&&JSTL标签库详解

    今天来看一下自定义标签的内容,自定义标签是JavaWeb的一部分非常重要的核心功能,我们之前就说过,JSP规范说的很清楚,就是Jsp页面中禁止编写一行Java代码,就是最好不要有Java脚本片段,下面 ...

  6. NX二次开发-UFUN读取本地文本文档uc4514a

    1 NX9+VS2012 2 3 #include <uf.h> 4 #include <uf_cfi.h> 5 #include <uf_ui.h> 6 7 us ...

  7. 笨办法学Python记录--习题1-11

    20140412(习题1-10),和打印较劲: 1. 读这本书时没有按照要求安装Python2,我选择的是最新版3.4.0(官方release),然后悲剧发现完全不兼容,现在摘录2,3区别: 这个星期 ...

  8. Go语言中new()和 make()的区别详解

    概述 Go 语言中的 new 和 make 一直是新手比较容易混淆的东西,咋一看很相似.不过解释两者之间的不同也非常容易. new 的主要特性 首先 new 是内建函数,你可以从 http://gol ...

  9. BackgroundWorker study

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. Spring源码由浅入深系列二 类结构

    BeanFactory 上一章中,我们提过Spring的依赖注入容器是BeanFactory.BeanFactory是一个基础接口,它有一个默认实现类:DefaultListableBeanFacto ...